index.vue 13 KB

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