dialogComponent.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <template>
  2. <div class="aa">
  3. <el-dialog
  4. :title="dialogTitle"
  5. v-model="showDialog"
  6. @open="open()"
  7. @close="closeDialog(0)"
  8. >
  9. <el-form
  10. ref="formInfo"
  11. :model="form"
  12. class="demo-form-inline"
  13. label-width="150px"
  14. :rules="rules"
  15. >
  16. <el-form-item label="" prop="aaa">
  17. <!-- <div>
  18. <el-checkbox
  19. v-model="checked1"
  20. label="展开/折叠"
  21. size="large"
  22. @change="handleExpandChange"
  23. />
  24. <el-checkbox v-model="checked2" label="全选/全不选" size="large" />
  25. <el-checkbox v-model="checked3" label="父子联动" size="large"/>
  26. </div> -->
  27. <el-tree
  28. v-if="data.length"
  29. :data="data"
  30. :props="defaultProps"
  31. @node-click="handleNodeClick"
  32. show-checkbox
  33. node-key="id"
  34. :default-expand-all="isExpand"
  35. :default-checked-keys="checkedArr"
  36. :check-strictly="isStrictly"
  37. @check="currentChecked"
  38. />
  39. <br />
  40. <div style="text-align: right">
  41. <el-button @click="closeDialog(0)">取消</el-button>
  42. <el-button type="primary" @click="submitForm(formInfo)">
  43. 保存
  44. </el-button>
  45. </div>
  46. </el-form-item>
  47. </el-form>
  48. </el-dialog>
  49. </div>
  50. </template>
  51. <script>
  52. import { useStore } from 'vuex'
  53. import { defineComponent, ref, watchEffect, watch, onMounted } from 'vue'
  54. import * as api from '@/api/tenantManage/authConfig.js'
  55. import { ElMessage } from 'element-plus'
  56. // import { parseTime } from '@/utils'
  57. // import { validatorPhone, parseTime, isEmail } from '@/utils'
  58. export default defineComponent({
  59. name: 'DialogComponent',
  60. emits: ['closeDialog'],
  61. props: {
  62. show_Dialog: Boolean,
  63. dialogTitle: String,
  64. itemInfo: {
  65. type: Object,
  66. default: function () {
  67. return {}
  68. },
  69. },
  70. },
  71. setup(props, { emit }) {
  72. const store = useStore()
  73. const beginTime = ref('')
  74. const showDialog = ref(false)
  75. const form = ref({})
  76. const formInfo = ref(null)
  77. const isExpand = ref(false)
  78. const isStrictly = ref(false)
  79. const getPlatformBoxList = ref([])
  80. const checked1 = ref(false)
  81. const checked2 = ref(false)
  82. const checked3 = ref(false)
  83. const checkedArr = ref([])
  84. const data = ref([])
  85. const handleNodeClick = (data, obj, node) => {
  86. data, node
  87. console.log(data)
  88. }
  89. const currentChecked = (nodeObj, SelectedObj) => {
  90. nodeObj, SelectedObj
  91. console.log('SelectedObj.checkedNodes')
  92. console.log(SelectedObj.checkedNodes)
  93. checkedArr.value = []
  94. SelectedObj.checkedNodes.forEach((item) => {
  95. checkedArr.value.push(item.id)
  96. })
  97. console.log(checkedArr.value)
  98. }
  99. //展开合并
  100. const handleExpandChange = () => {
  101. data.value = []
  102. if (checked1.value) {
  103. isExpand.value = true
  104. setTimeout(function () {
  105. data.value = [
  106. {
  107. label: 'Level one 1',
  108. children: [
  109. {
  110. label: 'Level two 1-1',
  111. children: [
  112. {
  113. label: 'Level three 1-1-1',
  114. },
  115. ],
  116. },
  117. ],
  118. },
  119. {
  120. label: 'Level one 2',
  121. children: [
  122. {
  123. label: 'Level two 2-1',
  124. children: [
  125. {
  126. label: 'Level three 2-1-1',
  127. },
  128. ],
  129. },
  130. {
  131. label: 'Level two 2-2',
  132. children: [
  133. {
  134. label: 'Level three 2-2-1',
  135. },
  136. ],
  137. },
  138. ],
  139. },
  140. {
  141. label: 'Level one 3',
  142. children: [
  143. {
  144. label: 'Level two 3-1',
  145. children: [
  146. {
  147. label: 'Level three 3-1-1',
  148. },
  149. ],
  150. },
  151. {
  152. label: 'Level two 3-2',
  153. children: [
  154. {
  155. label: 'Level three 3-2-1',
  156. },
  157. ],
  158. },
  159. ],
  160. },
  161. ]
  162. }, 10)
  163. } else {
  164. isExpand.value = false
  165. setTimeout(function () {
  166. data.value = [
  167. {
  168. label: 'Level one 1',
  169. children: [
  170. {
  171. label: 'Level two 1-1',
  172. children: [
  173. {
  174. label: 'Level three 1-1-1',
  175. },
  176. ],
  177. },
  178. ],
  179. },
  180. {
  181. label: 'Level one 2',
  182. children: [
  183. {
  184. label: 'Level two 2-1',
  185. children: [
  186. {
  187. label: 'Level three 2-1-1',
  188. },
  189. ],
  190. },
  191. {
  192. label: 'Level two 2-2',
  193. children: [
  194. {
  195. label: 'Level three 2-2-1',
  196. },
  197. ],
  198. },
  199. ],
  200. },
  201. {
  202. label: 'Level one 3',
  203. children: [
  204. {
  205. label: 'Level two 3-1',
  206. children: [
  207. {
  208. label: 'Level three 3-1-1',
  209. },
  210. ],
  211. },
  212. {
  213. label: 'Level two 3-2',
  214. children: [
  215. {
  216. label: 'Level three 3-2-1',
  217. },
  218. ],
  219. },
  220. ],
  221. },
  222. ]
  223. }, 10)
  224. }
  225. }
  226. //全选全不选
  227. const handleCheckedChange = () => {
  228. data.value = []
  229. if (checked2.value) {
  230. isExpand.value = true
  231. setTimeout(function () {
  232. data.value = [
  233. {
  234. label: 'Level one 1',
  235. children: [
  236. {
  237. label: 'Level two 1-1',
  238. children: [
  239. {
  240. label: 'Level three 1-1-1',
  241. },
  242. ],
  243. },
  244. ],
  245. },
  246. {
  247. label: 'Level one 2',
  248. children: [
  249. {
  250. label: 'Level two 2-1',
  251. children: [
  252. {
  253. label: 'Level three 2-1-1',
  254. },
  255. ],
  256. },
  257. {
  258. label: 'Level two 2-2',
  259. children: [
  260. {
  261. label: 'Level three 2-2-1',
  262. },
  263. ],
  264. },
  265. ],
  266. },
  267. {
  268. label: 'Level one 3',
  269. children: [
  270. {
  271. label: 'Level two 3-1',
  272. children: [
  273. {
  274. label: 'Level three 3-1-1',
  275. },
  276. ],
  277. },
  278. {
  279. label: 'Level two 3-2',
  280. children: [
  281. {
  282. label: 'Level three 3-2-1',
  283. },
  284. ],
  285. },
  286. ],
  287. },
  288. ]
  289. }, 10)
  290. } else {
  291. isExpand.value = false
  292. setTimeout(function () {
  293. data.value = [
  294. {
  295. label: 'Level one 1',
  296. children: [
  297. {
  298. label: 'Level two 1-1',
  299. children: [
  300. {
  301. label: 'Level three 1-1-1',
  302. },
  303. ],
  304. },
  305. ],
  306. },
  307. {
  308. label: 'Level one 2',
  309. children: [
  310. {
  311. label: 'Level two 2-1',
  312. children: [
  313. {
  314. label: 'Level three 2-1-1',
  315. },
  316. ],
  317. },
  318. {
  319. label: 'Level two 2-2',
  320. children: [
  321. {
  322. label: 'Level three 2-2-1',
  323. },
  324. ],
  325. },
  326. ],
  327. },
  328. {
  329. label: 'Level one 3',
  330. children: [
  331. {
  332. label: 'Level two 3-1',
  333. children: [
  334. {
  335. label: 'Level three 3-1-1',
  336. },
  337. ],
  338. },
  339. {
  340. label: 'Level two 3-2',
  341. children: [
  342. {
  343. label: 'Level three 3-2-1',
  344. },
  345. ],
  346. },
  347. ],
  348. },
  349. ]
  350. }, 10)
  351. }
  352. }
  353. const handleStrictlyChange = () => {
  354. if (checked3.value) {
  355. isStrictly.value = false
  356. setTimeout(function () {
  357. data.value = [
  358. {
  359. label: 'Level one 1',
  360. children: [
  361. {
  362. label: 'Level two 1-1',
  363. children: [
  364. {
  365. label: 'Level three 1-1-1',
  366. },
  367. ],
  368. },
  369. ],
  370. },
  371. {
  372. label: 'Level one 2',
  373. children: [
  374. {
  375. label: 'Level two 2-1',
  376. children: [
  377. {
  378. label: 'Level three 2-1-1',
  379. },
  380. ],
  381. },
  382. {
  383. label: 'Level two 2-2',
  384. children: [
  385. {
  386. label: 'Level three 2-2-1',
  387. },
  388. ],
  389. },
  390. ],
  391. },
  392. {
  393. label: 'Level one 3',
  394. children: [
  395. {
  396. label: 'Level two 3-1',
  397. children: [
  398. {
  399. label: 'Level three 3-1-1',
  400. },
  401. ],
  402. },
  403. {
  404. label: 'Level two 3-2',
  405. children: [
  406. {
  407. label: 'Level three 3-2-1',
  408. },
  409. ],
  410. },
  411. ],
  412. },
  413. ]
  414. }, 10)
  415. } else {
  416. isStrictly.value = true
  417. setTimeout(function () {}, 10)
  418. }
  419. }
  420. const roleValid = (rule, value, callback) => {
  421. rule
  422. if (value.length === 0) {
  423. callback(new Error('角色不能为空'))
  424. } else {
  425. callback()
  426. }
  427. }
  428. // 保存操作
  429. const submitForm = () => {
  430. if (checkedArr.value.length) {
  431. api.updateMenu({
  432. "tenantId":form.value.id,
  433. "menuIds":checkedArr.value
  434. }).then((requset) => {
  435. if (requset.status === 'SUCCESS') {
  436. ElMessage.success({
  437. message: '保存成功',
  438. type: 'success',
  439. })
  440. closeDialog()
  441. } else {
  442. ElMessage.error(requset.msg)
  443. }
  444. })
  445. } else {
  446. ElMessage.warning('请至少选择一个权限保存')
  447. }
  448. }
  449. const open = () => {
  450. form.value = props.itemInfo
  451. console.log('form.value')
  452. console.log(form.value)
  453. getMenuList()
  454. }
  455. // 关闭弹框
  456. const closeDialog = (flag) => {
  457. resetForm()
  458. showDialog.value = false
  459. emit('closeDialog', flag)
  460. checkedArr.value=[]
  461. }
  462. function resetForm() {
  463. formInfo.value.resetFields()
  464. }
  465. //树结构下拉
  466. function getMenuList() {
  467. api
  468. .getMenuList({
  469. tenantId: form.value.id,
  470. platformId: form.value.systemName,
  471. })
  472. .then((requset) => {
  473. if (requset.status === 'SUCCESS') {
  474. var jsona = JSON.stringify(requset.data.menus)
  475. var jsonb = jsona.replace(/"menu"/g, '"label"')
  476. jsonb = jsonb.replace(/"authority"/g, '"children"')
  477. jsonb = jsonb.replace(/"name"/g, '"label"')
  478. var jsonc = JSON.parse(jsonb)
  479. data.value = jsonc
  480. console.log('data.value')
  481. console.log(data.value)
  482. checkedArr.value = requset.data.checkedKeys
  483. console.log( 'checkedArr.value')
  484. console.log( checkedArr.value)
  485. } else {
  486. ElMessage.error(requset.msg)
  487. }
  488. })
  489. }
  490. //监听变化
  491. watch(
  492. () => checked1.value,
  493. (newVal) => {
  494. console.log(newVal)
  495. },
  496. { lazy: true }
  497. )
  498. watchEffect((fn, options) => {
  499. fn, options
  500. showDialog.value = props.show_Dialog
  501. })
  502. //禁止选择以前的时间
  503. const pickerEndDate = (time) => {
  504. const timeRange = 1 * 24 * 60 * 60 * 1000
  505. return time.getTime() <= Date.now() - timeRange * 1
  506. }
  507. onMounted(() => {})
  508. return {
  509. pickerEndDate,
  510. roleValid,
  511. submitForm,
  512. closeDialog,
  513. open,
  514. store,
  515. beginTime,
  516. showDialog,
  517. checked: true,
  518. form,
  519. formInfo,
  520. getPlatformBoxList,
  521. handleNodeClick,
  522. data,
  523. isExpand,
  524. isStrictly,
  525. checked1,
  526. checked2,
  527. checked3,
  528. handleExpandChange,
  529. handleCheckedChange,
  530. handleStrictlyChange,
  531. checkedArr,
  532. currentChecked,
  533. rules: {
  534. }
  535. }
  536. },
  537. })
  538. </script>
  539. <style scoped lang="scss">
  540. .el-input,
  541. .el-select,
  542. .el-date-editor.el-input,
  543. .el-date-editor.el-input__inner {
  544. width: 240px;
  545. }
  546. .el-form-item {
  547. margin: 0 0 20px !important;
  548. }
  549. // label样式
  550. .el-form-item__label {
  551. width: 120px !important;
  552. }
  553. .el-form-item__content {
  554. margin-left: 100px;
  555. }
  556. .demo-form-inline .el-form-item:not(.user-layout .el-form-item) {
  557. // margin: 0 auto 20px 55px;
  558. }
  559. .el-form-item:not(.user-layout .el-form-item) {
  560. max-width: 100%;
  561. }
  562. .el-tree {
  563. border: 1px solid #c0c4cc;
  564. padding: 15px;
  565. }
  566. // .aa {
  567. // ::v-deep .el-form-item--small .el-form-item__label {
  568. // line-height: 15px !important;
  569. // }
  570. // }
  571. </style>
  572. <style>
  573. </style>