123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610 |
- <template>
- <div class="aa">
- <el-dialog
- :title="dialogTitle"
- v-model="showDialog"
- @open="open()"
- @close="closeDialog(0)"
- >
- <el-form
- ref="formInfo"
- :model="form"
- class="demo-form-inline"
- label-width="150px"
- :rules="rules"
- >
- <el-form-item label="" prop="aaa">
- <!-- <div>
- <el-checkbox
- v-model="checked1"
- label="展开/折叠"
- size="large"
- @change="handleExpandChange"
- />
- <el-checkbox v-model="checked2" label="全选/全不选" size="large" />
- <el-checkbox v-model="checked3" label="父子联动" size="large"/>
- </div> -->
- <el-tree
- v-if="data.length"
- :data="data"
- :props="defaultProps"
- @node-click="handleNodeClick"
- show-checkbox
- node-key="id"
- :default-expand-all="isExpand"
- :default-checked-keys="checkedArr"
- :check-strictly="isStrictly"
- @check="currentChecked"
- />
- <br />
- <div style="text-align: right">
- <el-button @click="closeDialog(0)">取消</el-button>
- <el-button type="primary" @click="submitForm(formInfo)">
- 保存
- </el-button>
- </div>
- </el-form-item>
- </el-form>
- </el-dialog>
- </div>
- </template>
- <script>
- import { useStore } from 'vuex'
- import { defineComponent, ref, watchEffect, watch, onMounted } from 'vue'
- import * as api from '@/api/tenantManage/authConfig.js'
- import { ElMessage } from 'element-plus'
- // import { parseTime } from '@/utils'
- // import { validatorPhone, parseTime, isEmail } from '@/utils'
- export default defineComponent({
- name: 'DialogComponent',
- emits: ['closeDialog'],
- props: {
- show_Dialog: Boolean,
- dialogTitle: String,
- itemInfo: {
- type: Object,
- default: function () {
- return {}
- },
- },
- },
- setup(props, { emit }) {
- const store = useStore()
- const beginTime = ref('')
- const showDialog = ref(false)
- const form = ref({})
- const formInfo = ref(null)
- const isExpand = ref(false)
- const isStrictly = ref(false)
- const getPlatformBoxList = ref([])
- const checked1 = ref(false)
- const checked2 = ref(false)
- const checked3 = ref(false)
- const checkedArr = ref([])
- const data = ref([])
- const handleNodeClick = (data, obj, node) => {
- data, node
- console.log(data)
- }
- const currentChecked = (nodeObj, SelectedObj) => {
- nodeObj, SelectedObj
- console.log('SelectedObj.checkedNodes')
- console.log(SelectedObj.checkedNodes)
- checkedArr.value = []
-
- SelectedObj.checkedNodes.forEach((item) => {
- checkedArr.value.push(item.id)
- })
- console.log(checkedArr.value)
- }
- //展开合并
- const handleExpandChange = () => {
- data.value = []
- if (checked1.value) {
- isExpand.value = true
- setTimeout(function () {
- data.value = [
- {
- label: 'Level one 1',
- children: [
- {
- label: 'Level two 1-1',
- children: [
- {
- label: 'Level three 1-1-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 2',
- children: [
- {
- label: 'Level two 2-1',
- children: [
- {
- label: 'Level three 2-1-1',
- },
- ],
- },
- {
- label: 'Level two 2-2',
- children: [
- {
- label: 'Level three 2-2-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 3',
- children: [
- {
- label: 'Level two 3-1',
- children: [
- {
- label: 'Level three 3-1-1',
- },
- ],
- },
- {
- label: 'Level two 3-2',
- children: [
- {
- label: 'Level three 3-2-1',
- },
- ],
- },
- ],
- },
- ]
- }, 10)
- } else {
- isExpand.value = false
- setTimeout(function () {
- data.value = [
- {
- label: 'Level one 1',
- children: [
- {
- label: 'Level two 1-1',
- children: [
- {
- label: 'Level three 1-1-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 2',
- children: [
- {
- label: 'Level two 2-1',
- children: [
- {
- label: 'Level three 2-1-1',
- },
- ],
- },
- {
- label: 'Level two 2-2',
- children: [
- {
- label: 'Level three 2-2-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 3',
- children: [
- {
- label: 'Level two 3-1',
- children: [
- {
- label: 'Level three 3-1-1',
- },
- ],
- },
- {
- label: 'Level two 3-2',
- children: [
- {
- label: 'Level three 3-2-1',
- },
- ],
- },
- ],
- },
- ]
- }, 10)
- }
- }
- //全选全不选
- const handleCheckedChange = () => {
- data.value = []
- if (checked2.value) {
- isExpand.value = true
- setTimeout(function () {
- data.value = [
- {
- label: 'Level one 1',
- children: [
- {
- label: 'Level two 1-1',
- children: [
- {
- label: 'Level three 1-1-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 2',
- children: [
- {
- label: 'Level two 2-1',
- children: [
- {
- label: 'Level three 2-1-1',
- },
- ],
- },
- {
- label: 'Level two 2-2',
- children: [
- {
- label: 'Level three 2-2-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 3',
- children: [
- {
- label: 'Level two 3-1',
- children: [
- {
- label: 'Level three 3-1-1',
- },
- ],
- },
- {
- label: 'Level two 3-2',
- children: [
- {
- label: 'Level three 3-2-1',
- },
- ],
- },
- ],
- },
- ]
- }, 10)
- } else {
- isExpand.value = false
- setTimeout(function () {
- data.value = [
- {
- label: 'Level one 1',
- children: [
- {
- label: 'Level two 1-1',
- children: [
- {
- label: 'Level three 1-1-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 2',
- children: [
- {
- label: 'Level two 2-1',
- children: [
- {
- label: 'Level three 2-1-1',
- },
- ],
- },
- {
- label: 'Level two 2-2',
- children: [
- {
- label: 'Level three 2-2-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 3',
- children: [
- {
- label: 'Level two 3-1',
- children: [
- {
- label: 'Level three 3-1-1',
- },
- ],
- },
- {
- label: 'Level two 3-2',
- children: [
- {
- label: 'Level three 3-2-1',
- },
- ],
- },
- ],
- },
- ]
- }, 10)
- }
- }
- const handleStrictlyChange = () => {
- if (checked3.value) {
- isStrictly.value = false
- setTimeout(function () {
- data.value = [
- {
- label: 'Level one 1',
- children: [
- {
- label: 'Level two 1-1',
- children: [
- {
- label: 'Level three 1-1-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 2',
- children: [
- {
- label: 'Level two 2-1',
- children: [
- {
- label: 'Level three 2-1-1',
- },
- ],
- },
- {
- label: 'Level two 2-2',
- children: [
- {
- label: 'Level three 2-2-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 3',
- children: [
- {
- label: 'Level two 3-1',
- children: [
- {
- label: 'Level three 3-1-1',
- },
- ],
- },
- {
- label: 'Level two 3-2',
- children: [
- {
- label: 'Level three 3-2-1',
- },
- ],
- },
- ],
- },
- ]
- }, 10)
- } else {
- isStrictly.value = true
- setTimeout(function () {}, 10)
- }
- }
- const roleValid = (rule, value, callback) => {
- rule
- if (value.length === 0) {
- callback(new Error('角色不能为空'))
- } else {
- callback()
- }
- }
- // 保存操作
- const submitForm = () => {
- if (checkedArr.value.length) {
- api.updateMenu({
- "tenantId":form.value.id,
- "menuIds":checkedArr.value
- }).then((requset) => {
- if (requset.status === 'SUCCESS') {
- ElMessage.success({
- message: '保存成功',
- type: 'success',
- })
- closeDialog()
- } else {
- ElMessage.error(requset.msg)
- }
- })
- } else {
- ElMessage.warning('请至少选择一个权限保存')
-
- }
- }
- const open = () => {
- form.value = props.itemInfo
- console.log('form.value')
- console.log(form.value)
- getMenuList()
- }
- // 关闭弹框
- const closeDialog = (flag) => {
- resetForm()
- showDialog.value = false
- emit('closeDialog', flag)
- checkedArr.value=[]
- }
- function resetForm() {
- formInfo.value.resetFields()
- }
- //树结构下拉
- function getMenuList() {
- api
- .getMenuList({
- tenantId: form.value.id,
- platformId: form.value.systemName,
- })
- .then((requset) => {
- if (requset.status === 'SUCCESS') {
- var jsona = JSON.stringify(requset.data.menus)
- var jsonb = jsona.replace(/"menu"/g, '"label"')
- jsonb = jsonb.replace(/"authority"/g, '"children"')
- jsonb = jsonb.replace(/"name"/g, '"label"')
- var jsonc = JSON.parse(jsonb)
- data.value = jsonc
- console.log('data.value')
- console.log(data.value)
- checkedArr.value = requset.data.checkedKeys
- console.log( 'checkedArr.value')
- console.log( checkedArr.value)
-
- } else {
- ElMessage.error(requset.msg)
- }
- })
- }
- //监听变化
- watch(
- () => checked1.value,
- (newVal) => {
- console.log(newVal)
- },
- { lazy: true }
- )
- watchEffect((fn, options) => {
- fn, options
- showDialog.value = props.show_Dialog
- })
- //禁止选择以前的时间
- const pickerEndDate = (time) => {
- const timeRange = 1 * 24 * 60 * 60 * 1000
- return time.getTime() <= Date.now() - timeRange * 1
- }
- onMounted(() => {})
- return {
- pickerEndDate,
- roleValid,
- submitForm,
- closeDialog,
- open,
- store,
- beginTime,
- showDialog,
- checked: true,
- form,
- formInfo,
- getPlatformBoxList,
- handleNodeClick,
- data,
- isExpand,
- isStrictly,
- checked1,
- checked2,
- checked3,
- handleExpandChange,
- handleCheckedChange,
- handleStrictlyChange,
- checkedArr,
- currentChecked,
- rules: {
- }
- }
- },
- })
- </script>
-
- <style scoped lang="scss">
- .el-input,
- .el-select,
- .el-date-editor.el-input,
- .el-date-editor.el-input__inner {
- width: 240px;
- }
- .el-form-item {
- margin: 0 0 20px !important;
- }
- // label样式
- .el-form-item__label {
- width: 120px !important;
- }
- .el-form-item__content {
- margin-left: 100px;
- }
- .demo-form-inline .el-form-item:not(.user-layout .el-form-item) {
- // margin: 0 auto 20px 55px;
- }
- .el-form-item:not(.user-layout .el-form-item) {
- max-width: 100%;
- }
- .el-tree {
- border: 1px solid #c0c4cc;
- padding: 15px;
- }
- // .aa {
- // ::v-deep .el-form-item--small .el-form-item__label {
- // line-height: 15px !important;
- // }
- // }
- </style>
- <style>
- </style>
|