index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. <template>
  2. <div
  3. id="TradingDetailedInfoAdd"
  4. v-loading="loading"
  5. element-loading-background="rgba(122, 122, 122, 0.8)"
  6. element-loading-text="Loading..."
  7. class="InfoBox"
  8. :class="{ active: dialogInfoTradingAdd }"
  9. >
  10. <div class="header">
  11. <span v-if="editor" class="title">{{ $t('Label.EditorRole') }}</span>
  12. <span v-else class="title">{{ $t('Label.AddRole') }}</span>
  13. <span class="close crm-cursor" @click="close">
  14. <el-icon><Close /></el-icon>
  15. </span>
  16. </div>
  17. <el-form ref="formRef" :rules="rules" :model="form" label-width="100PX">
  18. <el-form-item prop="name" :label="$t('Label.RoleName') + ':'">
  19. <el-input
  20. v-model="form.name"
  21. :placeholder="$t('Placeholder.Input')"
  22. @input="selectChange"
  23. ></el-input>
  24. </el-form-item>
  25. <el-form-item prop="departmentId" :label="$t('Label.RoleGroup') + ':'">
  26. <el-select
  27. v-model="form.departmentId"
  28. class="crm_search_down"
  29. :placeholder="$t('Placeholder.Choose')"
  30. @change="selectChange"
  31. >
  32. <el-option
  33. v-for="(item, index) in group"
  34. :key="index"
  35. :label="item.name"
  36. :value="item.id"
  37. ></el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item class="authorityBox" :label="$t('Label.permissions') + ':'">
  41. <div
  42. style="
  43. border: 1px solid #dcdfe6;
  44. padding: 5px 2px;
  45. display: flex;
  46. flex-wrap: wrap;
  47. justify-content: flex-end;
  48. width: 100%;
  49. "
  50. >
  51. <el-button
  52. v-if="role_system"
  53. style="padding-right: 4px"
  54. type="text"
  55. @click="() => append('one')"
  56. >
  57. {{ $t('R-OneNodeAdd') }}
  58. </el-button>
  59. <el-tree
  60. ref="treeRef"
  61. style="width: 100%"
  62. :data="roleTreeDate"
  63. show-checkbox
  64. :props="defaultProps"
  65. node-key="tId"
  66. :default-checked-keys="defaultSelect"
  67. @check="handleCheck"
  68. >
  69. <template #default="{ node, data }">
  70. <span class="custom-tree-node">
  71. <span>{{ node.label }}</span>
  72. <span v-if="role_system">
  73. <el-icon @click="() => append(data)"><CirclePlus /></el-icon>
  74. <el-icon @click="() => update(data)"><Edit /></el-icon>
  75. <el-icon @click="() => remove(data)"><Delete /></el-icon>
  76. </span>
  77. </span>
  78. </template>
  79. </el-tree>
  80. </div>
  81. </el-form-item>
  82. </el-form>
  83. <el-button :loading="addLoading" @click="confirm">{{ $t('Btn.Confirm') }}</el-button>
  84. <el-dialog
  85. v-model="dialogCheck"
  86. :title="dialogCheck_form.title"
  87. center
  88. append-to-body
  89. width="600"
  90. custom-class="dialog_header_w"
  91. @close="cancel"
  92. >
  93. <div class="dia-content">
  94. <el-form
  95. ref="dialogCheckFormRef"
  96. :model="dialogCheck_form"
  97. :rules="rules"
  98. label-width="135px"
  99. class="dialogCheck_form"
  100. >
  101. <el-form-item
  102. v-if="dialogCheck_form.typeIndex1 != 3"
  103. prop="name"
  104. :label="$t('Label.AuthorityName') + ':'"
  105. >
  106. <el-input
  107. v-model="dialogCheck_form.name"
  108. style="width: 400px"
  109. :placeholder="$t('Placeholder.Input')"
  110. ></el-input>
  111. </el-form-item>
  112. <el-form-item
  113. v-if="dialogCheck_form.typeIndex != 3 && dialogCheck_form.typeIndex1 != 3"
  114. prop="link"
  115. :label="$t('Label.Url') + ':'"
  116. >
  117. <el-input
  118. v-model.trim="dialogCheck_form.link"
  119. style="width: 400px"
  120. :placeholder="$t('Placeholder.Input')"
  121. ></el-input>
  122. </el-form-item>
  123. <el-form-item
  124. v-if="dialogCheck_form.typeIndex != 3 && dialogCheck_form.typeIndex1 != 3"
  125. prop="icon"
  126. :label="$t('Label.Icon') + ':'"
  127. >
  128. <el-input
  129. v-model.trim="dialogCheck_form.icon"
  130. style="width: 400px"
  131. :placeholder="$t('Placeholder.Input')"
  132. ></el-input>
  133. </el-form-item>
  134. <el-form-item
  135. v-if="dialogCheck_form.typeIndex != 3 && dialogCheck_form.typeIndex1 != 3"
  136. prop="subIndex"
  137. :label="$t('Label.SubIndex') + ':'"
  138. >
  139. <el-input
  140. v-model.number.trim="dialogCheck_form.subIndex"
  141. style="width: 400px"
  142. :placeholder="$t('Placeholder.Input')"
  143. @input="selectChange"
  144. ></el-input>
  145. </el-form-item>
  146. <el-form-item
  147. v-if="dialogCheck_form.typeIndex == 3 && dialogCheck_form.typeIndex1 != 3"
  148. prop="action"
  149. :label="$t('Label.Url') + ':'"
  150. >
  151. <el-input
  152. v-model.trim="dialogCheck_form.action"
  153. style="width: 400px"
  154. :placeholder="$t('Placeholder.Input')"
  155. ></el-input>
  156. </el-form-item>
  157. <div
  158. v-if="dialogCheck_form.typeIndex1 == 3"
  159. style="text-align: center; font-size: 20px; padding: 25px 0"
  160. >
  161. {{ $t('Msg.Delete') }}
  162. </div>
  163. </el-form>
  164. </div>
  165. <template #footer>
  166. <div class="dialog-footer">
  167. <el-button v-if="dialogCheck_form.typeIndex1 == 1" type="primary" @click="toAppend()">
  168. {{ $t('Btn.Confirm') }}
  169. </el-button>
  170. <el-button v-if="dialogCheck_form.typeIndex1 == 2" type="primary" @click="toUpdate()">
  171. {{ $t('Btn.Confirm') }}
  172. </el-button>
  173. <el-button v-if="dialogCheck_form.typeIndex1 == 3" type="primary" @click="toRemove()">
  174. {{ $t('Btn.Confirm') }}
  175. </el-button>
  176. <el-button @click="cancel">{{ $t('Btn.Cancel') }}</el-button>
  177. </div>
  178. </template>
  179. </el-dialog>
  180. </div>
  181. </template>
  182. <script setup>
  183. import { ref, reactive, computed, onMounted, watch, inject } from 'vue'
  184. import { CirclePlus, Edit, Delete, Close } from '@element-plus/icons-vue'
  185. import { ElMessage, ElMessageBox } from 'element-plus'
  186. import ServiceUser from '@/service/user'
  187. import Config from '@/config/index'
  188. import { useI18n } from 'vue-i18n'
  189. const { Code } = Config
  190. const { t } = useI18n()
  191. const Session = inject('session')
  192. // props
  193. const props = defineProps({
  194. dialogInfoTradingAdd: {
  195. type: Boolean,
  196. default: false,
  197. },
  198. editor: {
  199. default: '',
  200. },
  201. myInfo: {
  202. default: '',
  203. },
  204. formList: {
  205. default: '',
  206. },
  207. })
  208. // emits
  209. const emit = defineEmits(['confirmToReload', 'closeAdd'])
  210. // refs
  211. const formRef = ref(null)
  212. const treeRef = ref(null)
  213. const dialogCheckFormRef = ref(null)
  214. // 新增loading
  215. const addLoading = ref(false)
  216. const loading = ref(false)
  217. // reactive data
  218. const form = reactive({})
  219. const group = ref([])
  220. const roleTreeDate = ref([])
  221. const defaultSelect = ref([])
  222. const data_check = ref([])
  223. const dialogCheck = ref(false)
  224. const dialogCheck_form = reactive({
  225. title: '',
  226. typeIndex: null,
  227. typeIndex1: null,
  228. pid: null,
  229. valid: null,
  230. id: null,
  231. subIndex: null,
  232. name: '',
  233. link: '',
  234. icon: '',
  235. action: '',
  236. ids: [],
  237. nodeId: null,
  238. code: '',
  239. })
  240. // constants
  241. const defaultProps = {
  242. children: 'children',
  243. label: 'name',
  244. }
  245. // computed
  246. const role_system = computed(() => {
  247. const user = JSON.parse(Session.Get('user', true) || '{}')
  248. return user.departmentId == null && user.roleName == 'ROLE_SYSTEM'
  249. })
  250. // rules
  251. const rules = reactive({
  252. name: [
  253. {
  254. required: true,
  255. message: t('Placeholder.Input'),
  256. trigger: 'blur',
  257. },
  258. ],
  259. link: [
  260. {
  261. required: true,
  262. message: t('Placeholder.Input'),
  263. trigger: 'blur',
  264. },
  265. ],
  266. icon: [
  267. {
  268. required: true,
  269. message: t('Placeholder.Input'),
  270. trigger: 'blur',
  271. },
  272. ],
  273. subIndex: [
  274. {
  275. required: true,
  276. message: t('Placeholder.Input'),
  277. trigger: 'blur',
  278. },
  279. ],
  280. action: [
  281. {
  282. required: true,
  283. message: t('Placeholder.Input'),
  284. trigger: 'blur',
  285. },
  286. ],
  287. })
  288. // methods
  289. const selectChange = () => {
  290. // 这里可能需要强制更新
  291. }
  292. const append = (data) => {
  293. console.log(data, 'append')
  294. if (data == 'one') {
  295. dialogCheck_form.title = t('R-OneNodeAdd')
  296. dialogCheck_form.typeIndex = 1
  297. dialogCheck_form.typeIndex1 = 1
  298. dialogCheck_form.pid = null
  299. dialogCheck_form.valid = 1
  300. } else {
  301. if (data.type == 0 && !data.pid) {
  302. dialogCheck_form.title = t('R-TwoNodeAdd')
  303. dialogCheck_form.typeIndex = 2
  304. dialogCheck_form.typeIndex1 = 1
  305. dialogCheck_form.pid = data.id
  306. dialogCheck_form.valid = 1
  307. } else {
  308. dialogCheck_form.title = t('R-BtnAdd')
  309. dialogCheck_form.typeIndex = 3
  310. dialogCheck_form.typeIndex1 = 1
  311. dialogCheck_form.nodeId = data.id
  312. dialogCheck_form.valid = 1
  313. }
  314. }
  315. dialogCheck.value = true
  316. }
  317. const update = (data) => {
  318. if (data.type == 0 && !data.pid) {
  319. dialogCheck_form.title = t('R-OneNodeAdd')
  320. dialogCheck_form.typeIndex = 1
  321. dialogCheck_form.typeIndex1 = 2
  322. dialogCheck_form.pid = null
  323. dialogCheck_form.valid = 1
  324. dialogCheck_form.id = data.id
  325. dialogCheck_form.subIndex = data.subIndex
  326. } else {
  327. if (data.type == 0 && data.pid) {
  328. dialogCheck_form.title = t('R-TwoNodeAdd')
  329. dialogCheck_form.typeIndex = 2
  330. dialogCheck_form.typeIndex1 = 2
  331. dialogCheck_form.pid = data.pid
  332. dialogCheck_form.valid = 1
  333. dialogCheck_form.id = data.id
  334. dialogCheck_form.subIndex = data.subIndex
  335. } else if (data.type == 1 && data.pid) {
  336. dialogCheck_form.title = t('R-BtnAdd')
  337. dialogCheck_form.typeIndex = 3
  338. dialogCheck_form.typeIndex1 = 2
  339. dialogCheck_form.nodeId = data.pid
  340. dialogCheck_form.valid = 1
  341. dialogCheck_form.id = data.id
  342. }
  343. }
  344. dialogCheck_form.name = data.name || ''
  345. dialogCheck_form.link = data.link || ''
  346. dialogCheck_form.icon = data.icon || ''
  347. dialogCheck_form.action = data.action || ''
  348. dialogCheck.value = true
  349. }
  350. const remove = (data) => {
  351. if (data.type == 0 && !data.pid) {
  352. dialogCheck_form.title = t('R-OneNodeAdd')
  353. dialogCheck_form.typeIndex = 1
  354. dialogCheck_form.typeIndex1 = 3
  355. dialogCheck_form.ids = [data.id]
  356. } else {
  357. if (data.type == 0 && data.pid) {
  358. dialogCheck_form.title = t('R-TwoNodeAdd')
  359. dialogCheck_form.typeIndex = 2
  360. dialogCheck_form.typeIndex1 = 3
  361. dialogCheck_form.ids = [data.id]
  362. } else if (data.type == 1 && data.pid) {
  363. dialogCheck_form.title = t('R-BtnAdd')
  364. dialogCheck_form.typeIndex = 3
  365. dialogCheck_form.typeIndex1 = 3
  366. dialogCheck_form.ids = [data.id]
  367. }
  368. }
  369. dialogCheck.value = true
  370. }
  371. const getDepartmentList = async () => {
  372. try {
  373. const res = await ServiceUser.departmentList({})
  374. if (res.code == Code.StatusOK) {
  375. group.value = res.data
  376. } else {
  377. ElMessage.error(res.msg)
  378. }
  379. } catch (error) {
  380. ElMessage.error(t('Msg.RequestError'))
  381. }
  382. }
  383. const handleCheck = (data, checked) => {
  384. data_check.value = []
  385. const checkedNodes = [...checked.checkedNodes, ...checked.halfCheckedNodes]
  386. checkedNodes.forEach((item) => {
  387. const dataItem = {
  388. name: item.code,
  389. id: item.id,
  390. pid: item.pid,
  391. type: item.type,
  392. }
  393. data_check.value.push(dataItem)
  394. })
  395. }
  396. const getDataCheck = () => {
  397. const data_c = []
  398. roleTreeDate.value.forEach((item) => {
  399. if (item.show) {
  400. data_c.push({
  401. name: item.code,
  402. id: item.id,
  403. pid: item.pid,
  404. type: item.type,
  405. })
  406. }
  407. if (item.children?.length) {
  408. item.children.forEach((item1) => {
  409. if (item1.show) {
  410. data_c.push({
  411. name: item1.code,
  412. id: item1.id,
  413. pid: item1.pid,
  414. type: item1.type,
  415. })
  416. }
  417. const btnsArray = item1.btns ? Object.values(item1.btns) : []
  418. btnsArray.forEach((item2) => {
  419. if (item2.show) {
  420. data_c.push({
  421. name: item2.code,
  422. id: item2.id,
  423. pid: item2.pid,
  424. type: item2.type,
  425. })
  426. }
  427. })
  428. })
  429. }
  430. })
  431. data_check.value = data_c
  432. }
  433. const cancel = () => {
  434. dialogCheck.value = false
  435. dialogCheckFormRef.value?.resetFields()
  436. }
  437. const toAppend = async () => {
  438. try {
  439. const valid = await dialogCheckFormRef?.value.validate()
  440. console.log(valid)
  441. console.log(dialogCheck_form)
  442. const { typeIndex } = dialogCheck_form
  443. if (valid) {
  444. if (typeIndex == 1 || typeIndex == 2) {
  445. dialogCheck_form.subIndex = Number(dialogCheck_form.subIndex)
  446. dialogCheck_form.code = dialogCheck_form.name
  447. const res = await ServiceUser.authorityNodeAdd({
  448. ...dialogCheck_form,
  449. })
  450. if (res.code == Code.StatusOK) {
  451. ElMessage.success(res.msg)
  452. } else {
  453. ElMessage.error(res.msg)
  454. }
  455. } else if (typeIndex == 3) {
  456. dialogCheck_form.code = dialogCheck_form.name
  457. let res = await ServiceUser.authorityActionAdd({
  458. ...dialogCheck_form,
  459. })
  460. if (res.code == Code.StatusOK) {
  461. ElMessage.success(res.msg)
  462. } else {
  463. ElMessage.error(res.msg)
  464. }
  465. }
  466. cancel()
  467. getRoleDetailAdd()
  468. }
  469. } catch (error) {
  470. console.error('表单验证失败:', error)
  471. }
  472. }
  473. const getRoleDetailUpdate = async () => {
  474. // 复制表单数据
  475. Object.assign(form, props.formList)
  476. try {
  477. const res = await ServiceUser.groupSingleUpdate({
  478. id: props.formList?.id || form.id,
  479. })
  480. if (res.code === Code.StatusOK) {
  481. // 处理角色树数据
  482. const processedData = processRoleTreeData(res.data)
  483. roleTreeDate.value = processedData.data
  484. defaultSelect.value = processedData.select
  485. } else {
  486. ElMessage.error(res.msg || t('Msg.RequestError'))
  487. }
  488. loading.value = false
  489. } catch (error) {
  490. console.error('获取角色详情失败:', error)
  491. ElMessage.error(t('Msg.RequestError'))
  492. }
  493. }
  494. // 处理角色树数据的函数(可以独立出来复用)
  495. const processRoleTreeData = (treeData) => {
  496. const select = []
  497. const processedData = treeData.map((item) => {
  498. // 处理一级节点
  499. const processedItem = {
  500. ...item,
  501. name: t(item.name),
  502. children: item.children ? processChildrenNodes(item.children, select) : [],
  503. }
  504. return processedItem
  505. })
  506. return {
  507. data: processedData,
  508. select,
  509. }
  510. }
  511. // 处理子节点
  512. const processChildrenNodes = (children, select) => {
  513. return children.map((child) => {
  514. // 处理二级节点
  515. const btnsArray = child.btns ? Object.values(child.btns) : []
  516. // 处理三级节点(按钮节点)
  517. const buttonNodes = btnsArray.map((btn) => {
  518. const buttonNode = {
  519. ...btn,
  520. name: t(btn.name),
  521. }
  522. // 如果按钮节点显示,添加到选中列表中
  523. if (buttonNode.show) {
  524. select.push(buttonNode.tId)
  525. }
  526. return buttonNode
  527. })
  528. const processedChild = {
  529. ...child,
  530. name: t(child.name),
  531. children: buttonNodes,
  532. }
  533. // 如果没有子节点且当前节点显示,添加到选中列表中
  534. if (!buttonNodes.length && processedChild.show) {
  535. select.push(processedChild.tId)
  536. }
  537. return processedChild
  538. })
  539. }
  540. const toUpdate = async () => {
  541. try {
  542. const valid = await dialogCheckFormRef.value.validate()
  543. if (valid) {
  544. const { typeIndex } = dialogCheck_form
  545. if (typeIndex == 1 || typeIndex == 2) {
  546. dialogCheck_form.subIndex = Number(dialogCheck_form.subIndex)
  547. dialogCheck_form.code = dialogCheck_form.name
  548. const res = await ServiceUser.authorityNodeUpdate({
  549. ...dialogCheck_form,
  550. })
  551. if (res.code == Code.StatusOK) {
  552. ElMessage.success(res.msg)
  553. } else {
  554. ElMessage.error(res.msg)
  555. }
  556. } else if (typeIndex == 3) {
  557. dialogCheck_form.code = dialogCheck_form.name
  558. let res = await ServiceUser.authorityActionUpdate({
  559. ...dialogCheck_form,
  560. })
  561. if (res.code == Code.StatusOK) {
  562. ElMessage.success(res.msg)
  563. } else {
  564. ElMessage.error(res.msg)
  565. }
  566. }
  567. cancel()
  568. getRoleDetailAdd()
  569. }
  570. } catch (error) {
  571. console.error('表单验证失败:', error)
  572. }
  573. }
  574. const toRemove = async () => {
  575. try {
  576. const valid = await dialogCheckFormRef.value.validate()
  577. if (valid) {
  578. const { typeIndex } = dialogCheck_form
  579. if (typeIndex == 1 || typeIndex == 2) {
  580. const res = await ServiceUser.authorityNodeDelete({
  581. ...dialogCheck_form,
  582. })
  583. if (res.code == Code.StatusOK) {
  584. ElMessage.success(res.msg)
  585. } else {
  586. ElMessage.error(res.msg)
  587. }
  588. } else if (typeIndex == 3) {
  589. let res = await ServiceUser.authorityActionDelete({
  590. ...dialogCheck_form,
  591. })
  592. if (res.code == Code.StatusOK) {
  593. ElMessage.success(res.msg)
  594. } else {
  595. ElMessage.error(res.msg)
  596. }
  597. }
  598. cancel()
  599. getRoleDetailAdd()
  600. }
  601. } catch (error) {
  602. console.error('表单验证失败:', error)
  603. }
  604. }
  605. const getRoleDetailAdd = async () => {
  606. try {
  607. const res = await ServiceUser.groupSingleAdd({})
  608. if (res.code == Code.StatusOK) {
  609. const data = res.data.map((item) => {
  610. return {
  611. ...item,
  612. name: t(item.name),
  613. children:
  614. item.children?.map((child) => ({
  615. ...child,
  616. name: t(child.name),
  617. children: child.btns
  618. ? Object.values(child.btns).map((btn) => ({
  619. ...btn,
  620. name: t(btn.name),
  621. }))
  622. : [],
  623. })) || [],
  624. }
  625. })
  626. roleTreeDate.value = data
  627. loading.value = false
  628. } else {
  629. ElMessage.error(res.msg)
  630. }
  631. } catch (error) {
  632. ElMessage.error(t('Msg.RequestError'))
  633. }
  634. }
  635. const confirm = () => {
  636. formRef.value.validate(async (valid) => {
  637. if (valid) {
  638. toConfirm()
  639. } else {
  640. return false
  641. }
  642. })
  643. }
  644. const toConfirm = () => {
  645. addLoading.value = true
  646. if (props.editor) {
  647. roleUpdate()
  648. } else {
  649. roleAdd()
  650. }
  651. }
  652. const roleAdd = async () => {
  653. let res = await ServiceUser.roleListAdd({
  654. data: data_check.value,
  655. code: 'ROLE_USER',
  656. ...form,
  657. })
  658. addLoading.value = false
  659. if (res.code == Code.StatusOK) {
  660. formRef.value.resetFields()
  661. roleTreeDate.value = []
  662. emit('confirmToReload')
  663. emit('closeAdd', false)
  664. ElMessage.success(t('Msg.Success'))
  665. } else {
  666. ElMessage.error(res.msg)
  667. }
  668. }
  669. const roleUpdate = async () => {
  670. if (!data_check.value.length) {
  671. getDataCheck()
  672. }
  673. let res = await ServiceUser.roleListUpdate({
  674. data: data_check.value,
  675. code: 'ROLE_USER',
  676. ...form,
  677. })
  678. addLoading.value = false
  679. if (res.code == Code.StatusOK) {
  680. roleTreeDate.value = []
  681. defaultSelect.value = []
  682. formRef.value.resetFields()
  683. emit('confirmToReload')
  684. emit('closeAdd', false)
  685. ElMessage.success(t('Msg.Success'))
  686. } else {
  687. ElMessage.error(res.msg)
  688. }
  689. }
  690. //提交成功后回调
  691. const confirmToReload = () => {
  692. emit('confirmToReload', true)
  693. }
  694. // watch for props changes
  695. watch(
  696. () => props.formList,
  697. (newVal) => {
  698. if (newVal) {
  699. Object.assign(form, newVal)
  700. }
  701. },
  702. { immediate: true }
  703. )
  704. watch(
  705. () => props.dialogInfoTradingAdd,
  706. async (newVal) => {
  707. loading.value = true
  708. if (newVal) {
  709. if (props.editor) {
  710. await getRoleDetailUpdate()
  711. } else {
  712. await getRoleDetailAdd()
  713. }
  714. }
  715. }
  716. )
  717. // lifecycle
  718. onMounted(async () => {
  719. // await Promise.all([getDepartmentList(), getRoleDetailAdd()])
  720. getDepartmentList()
  721. console.log(props, 'props')
  722. // 设置默认选中
  723. if (props.editor && props.formList?.id) {
  724. // 如果有编辑数据,设置默认选中项
  725. // 这里需要根据实际逻辑设置 defaultSelect.value
  726. }
  727. })
  728. </script>
  729. <style scoped></style>