index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <div class="container">
  3. <div class="head-title">
  4. <span> {{ route.meta.title }} </span>
  5. <a-button type="primary" @click="evAddMenu">{{ $t('global.newMenu') }}</a-button>
  6. </div>
  7. <a-space direction="vertical" :style="{ width: '100%' }">
  8. <a-upload :show-file-list="false" :custom-request="customRequest" />
  9. </a-space>
  10. <!-- default-expand-all-rows -->
  11. <a-table
  12. class="table"
  13. :columns="columns"
  14. :data="refData.dataSource"
  15. :pagination="false"
  16. row-key="id"
  17. :scroll="{ x: '120%' }"
  18. >
  19. <template #name="{ record }">
  20. <span> {{ getParseLang(record.name, lang.getLang) }} </span>
  21. <template v-if="record.permsArr && record.permsArr.length > 0">
  22. <a-tag v-for="item in record.permsArr" :key="item.id" class="tag-name">{{ item.name }}</a-tag>
  23. </template>
  24. </template>
  25. <template #refresh="{ record }">
  26. <span v-if="['1', '2'].includes(record.type)">{{
  27. record.refresh ? "是" : "否"
  28. }}</span>
  29. </template>
  30. <template #icon="{ record }">
  31. <!-- <a>123456789</a> -->
  32. <span v-if="!record.icon"></span>
  33. <svg-icon v-else class="icon" :icon="record.icon" />
  34. </template>
  35. <template #id="{ record }">
  36. <a
  37. href="javascript:;"
  38. class="a-link"
  39. style="margin-right: 1rem"
  40. @click="evEdit(record)"
  41. >编辑</a
  42. >
  43. <a-popconfirm
  44. content="确认删除该信息?"
  45. ok-text="确定"
  46. cancel-text="取消"
  47. @ok="evDelete(record.id)"
  48. >
  49. <a href="javascript:;" class="a-link">删除</a>
  50. </a-popconfirm>
  51. </template>
  52. </a-table>
  53. <a-modal
  54. v-model:visible="refData.visible"
  55. title="菜单信息"
  56. :centered="true"
  57. :width="700"
  58. :footer="false"
  59. simple
  60. >
  61. <div class="form-box">
  62. <a-form
  63. :model="refData.fromData"
  64. @submit-success="evHandleSubmit"
  65. >
  66. <a-form-item
  67. field="name"
  68. label="路由名称"
  69. :rules="[{ required: true, message: '请输入路由名称' }]"
  70. :validate-trigger="['change', 'input', 'blur']"
  71. >
  72. <!-- <a-input
  73. v-model="refData.fromData.name"
  74. placeholder="请输入路由名称"
  75. /> -->
  76. <MonacoEditor v-model="refData.fromData.name" />
  77. </a-form-item>
  78. <a-form-item
  79. field="menu_id"
  80. label="上级路由"
  81. :validate-trigger="['change', 'input', 'blur']"
  82. >
  83. <a-tree-select
  84. v-model="refData.fromData.menu_id"
  85. placeholder="一级菜单"
  86. :data="refData.menuTree"
  87. :allow-clear="true"
  88. :field-names="{
  89. children: 'children',
  90. title: 'name',
  91. key: 'id',
  92. }"
  93. :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
  94. />
  95. </a-form-item>
  96. <a-form-item
  97. field="path"
  98. label="路由标识"
  99. :rules="[{ required: true, message: '请输入路由标识' }]"
  100. :validate-trigger="['change', 'input', 'blur']"
  101. >
  102. <a-input
  103. v-model="refData.fromData.path"
  104. placeholder="请输入路由标识"
  105. />
  106. </a-form-item>
  107. <a-form-item
  108. v-if="!refData.fromData.menu_id"
  109. field="icon"
  110. label="路由图标"
  111. :rules="[{ required: true, message: '请选择路由图标' }]"
  112. :validate-trigger="['change', 'input', 'blur']"
  113. >
  114. <a-input
  115. v-model="refData.fromData.icon"
  116. placeholder="请设置菜单图标"
  117. >
  118. <template
  119. v-if="refData.fromData.icon"
  120. #suffix
  121. >
  122. <svg-icon class="input-icon" :icon="refData.fromData.icon" />
  123. </template>
  124. <template #append>
  125. <icon-settings class="icon-append" @click="evIconModal" />
  126. <!-- <setting-outlined class="icon-append" @click="evIconModal" /> -->
  127. </template>
  128. </a-input>
  129. </a-form-item>
  130. <a-form-item v-if="isUrlView" field="url" label="路由地址">
  131. <!-- :rules="[{ required: true, message: '请输入路由名称' }]"
  132. :validate-trigger="['change', 'input', 'blur']" -->
  133. <!--
  134. <a-select v-model:value="refData.fromData.url" placeholder="请选择路由地址">
  135. <a-select-option v-for="item in refData.menuList" :key="item" :value="item"> {{ item }}</a-select-option>
  136. </a-select> -->
  137. <a-select v-model="refData.fromData.url" :options="refData.menuList" :field-names="{ value: 'item', label: 'item' }" placeholder="请选择路由地址" />
  138. </a-form-item>
  139. <a-form-item v-if="isUrlView" label="权限标识">
  140. <div class="flex-col-body">
  141. <a-form-item
  142. v-for="(item, index) in refData.fromData.permsArr"
  143. :key="index"
  144. >
  145. <a-input v-model="item.name" placeholder="名称" />
  146. <a-input
  147. v-model="item.perms"
  148. style="margin-left: 1rem"
  149. placeholder="请输入权限标识"
  150. />
  151. <div class="flex-row-icon">
  152. <icon-close-circle-fill
  153. v-if="refData.fromData.permsArr.length > 1"
  154. @click="refData.fromData.permsArr.splice(index, 1)"
  155. />
  156. <icon-plus-circle-fill
  157. v-if="refData.fromData.permsArr.length - 1 === index"
  158. class="icon-plus-circle-fill"
  159. @click="
  160. refData.fromData.permsArr.push({
  161. menuName: '',
  162. perms: '',
  163. })
  164. "
  165. />
  166. </div>
  167. </a-form-item>
  168. </div>
  169. </a-form-item>
  170. <a-form-item v-if="isUrlView" name="refresh" label="缓存">
  171. <a-switch
  172. v-model:checked="refData.fromData.refresh"
  173. checked-value="1"
  174. unchecked-value="0"
  175. >
  176. <template #checked> ON </template>
  177. <template #unchecked> OFF </template>
  178. </a-switch>
  179. </a-form-item>
  180. <a-form-item
  181. name="sortNumber"
  182. label="序号"
  183. :rules="[{ required: true, message: '请输入序号' }]"
  184. :validate-trigger="['change', 'input', 'blur']"
  185. >
  186. <a-input-number v-model="refData.fromData.sortNumber" :min="0" />
  187. </a-form-item>
  188. <a-form-item>
  189. <div class="modal-footer">
  190. <a-button type="primary" size="large" html-type="submit"
  191. >确定</a-button
  192. >
  193. <a-button size="large" @click="evCancel"> 取消</a-button>
  194. </div>
  195. </a-form-item>
  196. </a-form>
  197. </div>
  198. </a-modal>
  199. <a-modal v-model:visible="refData.visibleIcon" simple :footer="false">
  200. <div class="font-view">
  201. <div
  202. v-for="(item, index) in refData.iconfontArr"
  203. :key="index"
  204. class="icon-box"
  205. >
  206. <svg-icon
  207. :icon="item.font_class"
  208. :class="{
  209. icon: true,
  210. 'icon-active': item.font_class === refData.fromData.icon,
  211. }"
  212. @click="evOnIconName(item.font_class)"
  213. />
  214. </div>
  215. </div>
  216. </a-modal>
  217. </div>
  218. </template>
  219. <script setup>
  220. import { onMounted, reactive, computed, ref, watch} from "vue";
  221. import { useRoute } from "vue-router";
  222. import { Message, Notification } from '@arco-design/web-vue'
  223. import MonacoEditor from "@/components/MonacoEditor/index.vue"
  224. import iconsvgJson from "@/assets/iconsvg/iconfont.json";
  225. import { useLangStore } from '@/store/modules/langStore'
  226. import { getParseLang } from '@/utils'
  227. import _ from "lodash";
  228. import { columns } from './config'
  229. import { systemSetMenu, systemFinMenuAll, systemDeleteMenu, systemUpdateMenu } from "@/api/path/system.api"
  230. import { useSystemStore } from '@/store/modules/systemStore'
  231. const route = useRoute();
  232. const lang = useLangStore()
  233. const systemStore = useSystemStore()
  234. const refData = reactive({
  235. visible: false,
  236. visibleIcon: false,
  237. dataSource: [],
  238. fromData: {
  239. name: "",
  240. parentId: undefined,
  241. menu_id: undefined,
  242. type: "0",
  243. url: "",
  244. sortNumber: 99,
  245. refresh: 0,
  246. permsArr: [{ name: "", perms: "" }],
  247. },
  248. menuTree: [],
  249. menuList: [],
  250. iconfontArr: []
  251. });
  252. const menuTreeList = ref([])
  253. const isUrlView = computed(() => {
  254. // if (refData.fromData.menu_id) {
  255. // const obj = menuTreeList.value.find(item => item.id == refData.fromData.menu_id)
  256. // return refData.fromData.menu_id && ["1", "2"].includes(obj.type);
  257. // }
  258. // return false;
  259. return true;
  260. });
  261. const fnTreeData = (data) => {
  262. return data.map((item) => {
  263. if (item.children && item.children.length > 0 && item.type !== "3") {
  264. item.children = item.children.sort((a, b) => {
  265. if (a.sortNumber === b.sortNumber) {
  266. return a.id - b.id;
  267. }
  268. return a.sortNumber - b.sortNumber;
  269. });
  270. item.children = fnTreeData(item.children);
  271. }
  272. if (item.type === '2') {
  273. item.permsArr = item.children;
  274. Reflect.deleteProperty(item, "children");
  275. }
  276. return item;
  277. });
  278. };
  279. const fnDeleteTreeSon = (data) => {
  280. return data.filter((item) => {
  281. item.name = getParseLang(item.name, lang.getLang)
  282. Reflect.deleteProperty(item, 'icon')
  283. if (item.children && item.children.length > 0) {
  284. item.children = fnDeleteTreeSon(item.children);
  285. }
  286. return ["1"].includes(item.type);
  287. });
  288. };
  289. const fnGetFormData = async () => {
  290. const arr = [];
  291. const comp = import.meta.glob("../../../views/**/index.vue");
  292. if (comp) {
  293. Object.keys(comp).forEach((key) => {
  294. arr.push(`${comp[key]}`. replace(/^.*import\("\/src\/([^?"]+).*$/, '$1'));
  295. });
  296. arr.push("views/system/menu/index.vue")
  297. refData.menuList = arr
  298. }
  299. };
  300. const evCancel = () => {
  301. refData.visibleIcon = false;
  302. refData.visible = false;
  303. };
  304. const evInitData = async () => {
  305. evCancel();
  306. const { data } = await systemFinMenuAll();
  307. const arr = fnTreeData(_.cloneDeep(data));
  308. refData.dataSource = arr
  309. refData.menuTree = fnDeleteTreeSon(_.cloneDeep(data));
  310. menuTreeList.value = fnGetTreeList(_.cloneDeep(data))
  311. };
  312. const fnGetTreeList = (data) => {
  313. return data.reduce((iter, val) => {
  314. if (["1"].includes(val.type)) {
  315. iter.push(val);
  316. }
  317. return val.children ? [...iter, ...fnGetTreeList(val.children)] : iter;
  318. }, []);
  319. };
  320. const evEdit = async (data) => {
  321. refData.fromData = data;
  322. if(!data.permsArr || data.permsArr.length == 0){
  323. refData.fromData.permsArr = [{ name: "", perms: "" }]
  324. }
  325. refData.visible = true;
  326. };
  327. const evHandleSubmit = async (values) => {
  328. const data = JSON.parse(JSON.stringify(values));
  329. data.type = "1"
  330. if (data.url) data.type = "2";
  331. if(data.id){
  332. await systemUpdateMenu(data)
  333. }else{
  334. await systemSetMenu(data);
  335. }
  336. evInitData();
  337. };
  338. const evDelete = async (id) => {
  339. await systemDeleteMenu({ id });
  340. evInitData();
  341. };
  342. const evAddMenu = async () => {
  343. refData.fromData = {
  344. name: `{
  345. "zh-CN": "",
  346. "en-US": "",
  347. "th-TH": ""
  348. }`,
  349. permsArr: [{ name: "", perms: "" }]
  350. };
  351. try {
  352. await fnGetFormData();
  353. } catch (e) {
  354. //
  355. }
  356. refData.visible = true;
  357. };
  358. const evIconModal = async () => {
  359. refData.iconfontArr = iconsvgJson.glyphs.filter((item) => {
  360. return ["menu", "Dh"].includes(item.font_class.split("-")[0]);
  361. });
  362. refData.visibleIcon = true;
  363. };
  364. const evOnIconName = (item) => {
  365. refData.fromData.icon = item;
  366. refData.fromData = { ...refData.fromData };
  367. refData.visibleIcon = false;
  368. Message.success({
  369. content: `选中 ${item}`,
  370. duration: 2000,
  371. });
  372. };
  373. // 上传
  374. const customRequest = async (option) => {
  375. const { file } = option.fileItem;
  376. // 上传
  377. const fileName = `thumbnail_${file.name}`
  378. const key = `test/${fileName}`
  379. const client = await systemStore.getSTSClient()
  380. const resClient = await client.putObject({
  381. key: key,
  382. body: file
  383. })
  384. if (resClient.statusCode === 200) {
  385. console.log('上传成功')
  386. console.log("resClient=",resClient)
  387. }
  388. };
  389. onMounted(() => {
  390. evInitData()
  391. });
  392. </script>
  393. <style scoped lang="less">
  394. .head-title {
  395. display: flex;
  396. justify-content: space-between;
  397. .fn-headTitleDiv();
  398. padding: 0.5rem 0;
  399. }
  400. .table {
  401. margin-top: 1.5rem;
  402. .tag-name {
  403. margin: 0.2rem;
  404. }
  405. .icon {
  406. font-size: 20px;
  407. }
  408. }
  409. .icon-append {
  410. &:hover {
  411. cursor: pointer;
  412. }
  413. }
  414. :deep(.arco-col-19) {
  415. flex: none !important;
  416. width: 340px !important;
  417. }
  418. .form-box {
  419. padding-left: 4rem;
  420. .flex-col-body {
  421. display: flex;
  422. flex-direction: column;
  423. .flex-row-icon {
  424. min-width: 35px;
  425. display: flex;
  426. justify-content: space-between;
  427. align-items: center;
  428. margin-left: 10px;
  429. .icon-plus-circle-fill {
  430. font-size: 16px;
  431. margin-left: 0.5rem;
  432. // color: @orange_1;
  433. &:hover {
  434. cursor: pointer;
  435. transform: scale(1.4);
  436. // color: @blue_0;
  437. }
  438. }
  439. svg:hover {
  440. cursor: pointer;
  441. transform: scale(1.4);
  442. // color: @red_0;
  443. }
  444. }
  445. }
  446. }
  447. .modal-footer {
  448. width: 150px;
  449. margin: 0 auto 16px auto;
  450. display: flex;
  451. justify-content: space-between;
  452. }
  453. .font-view {
  454. display: flex;
  455. flex-wrap: wrap;
  456. .icon-box {
  457. width: 30px;
  458. height: 30px;
  459. margin: 10px;
  460. .icon {
  461. width: 100%;
  462. height: 100%;
  463. font-size: 100px;
  464. transform: scale(1, 1);
  465. animation: mymove 1s;
  466. animation-fill-mode: forwards;
  467. color: #9696a0;
  468. cursor: pointer;
  469. &:hover,
  470. &.icon-active {
  471. background: #dbdbf3;
  472. transform: scale(1, 1);
  473. animation: mymove2 1s;
  474. animation-fill-mode: forwards;
  475. }
  476. }
  477. }
  478. }
  479. @keyframes mymove {
  480. 0% {
  481. transform: scale(1, 1);
  482. }
  483. 50% {
  484. transform: scale(1.2, 1.2);
  485. }
  486. 100% {
  487. transform: scale(1.1, 1.1);
  488. }
  489. }
  490. @keyframes mymove2 {
  491. 0% {
  492. transform: scale(1, 1);
  493. }
  494. 50% {
  495. transform: scale(1.3, 1.3);
  496. }
  497. 100% {
  498. transform: scale(1.1, 1.1);
  499. }
  500. }
  501. </style>