UserMenu.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <BasicDrawer
  3. :destroyOnClose="true"
  4. :maskClosable="true"
  5. v-bind="$attrs"
  6. @register="registerModal"
  7. title="常用菜单配置"
  8. width="100%"
  9. :showFooter="false"
  10. >
  11. <div class="flex">
  12. <div class="commonly">
  13. <div v-for="(row, i) in menuRoleData" :key="i">
  14. <div class="commonly-group"> {{ row.name }}</div>
  15. <div class="grid grid-cols-6 gap-2">
  16. <div
  17. class="commonly-item"
  18. v-for="(item, index) in row.menuVoList"
  19. :key="index"
  20. :class="{ 'commonly-item-active': menuCommonlyIds.includes(item.id) }"
  21. >
  22. <div class="flex flex-1 h-full" @click="handelClick(item)">
  23. <img
  24. style="width: 56px; height: 56px; object-fit: contain"
  25. :src="item.iconUrl || 'https://zhxy.cqtlzjzx.com/minio/static/service.png'"
  26. alt=""
  27. />
  28. <div class="ml-2 flex flex-1 flex-col truncate">
  29. <div class="commonly-item-title">
  30. <div> {{ item.title }} </div>
  31. </div>
  32. <div class="flex justify-between">
  33. <div class="commonly-item-desc">{{ item.remark }}</div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="commonly-item-tag">
  38. <div class="commonly-item-tag-d"></div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </BasicDrawer>
  46. </template>
  47. <script setup lang="ts">
  48. import { onMounted, ref } from 'vue';
  49. import { useDrawerInner, BasicDrawer } from '/@/components/Drawer';
  50. import {
  51. deleteSystemSystemMenuCommonlyUsed,
  52. getSystemMenuCommonlyUsedNopage,
  53. postSystemSystemMenuCommonlyUsed,
  54. } from '/@/services/apis/SystemMenuCommonlyUsedController';
  55. import { useMessage } from '/@/hooks/web/useMessage';
  56. import { getMenuServe } from '/@/services/apis/MenuController';
  57. const emits = defineEmits(['success', 'register']);
  58. const { createConfirm, createMessage } = useMessage();
  59. const menuRoleData = ref<Recordable[]>([]);
  60. const menuCommonlyData = ref<Recordable[]>([]);
  61. const menuCommonlyIds = ref<string[]>([]);
  62. const getMenuRole = async () => {
  63. menuRoleData.value = await getMenuServe({ systemType: 'system_pc' });
  64. };
  65. const getMenuCommonly = async () => {
  66. const data = await getSystemMenuCommonlyUsedNopage({});
  67. menuCommonlyData.value = data || [];
  68. menuCommonlyIds.value = menuCommonlyData.value.map((item) => item.menuId);
  69. };
  70. const [registerModal, { setDrawerProps }] = useDrawerInner(async () => {
  71. await getMenuCommonly();
  72. await getMenuRole();
  73. setDrawerProps({ confirmLoading: false });
  74. });
  75. const handelClick = async (item) => {
  76. if (menuCommonlyIds.value.includes(item.id)) {
  77. await deleteSystemSystemMenuCommonlyUsed([item.id]);
  78. menuCommonlyIds.value.splice(
  79. menuCommonlyIds.value.findIndex((row) => row === item.id),
  80. 1,
  81. );
  82. } else {
  83. await postSystemSystemMenuCommonlyUsed({ menuId: item.id });
  84. menuCommonlyIds.value.push(item.id);
  85. }
  86. emits('success');
  87. };
  88. const handleDelete = (record: any) => {
  89. createConfirm({
  90. iconType: 'warning',
  91. title: '温馨提醒',
  92. content: '是否删除该数据?',
  93. onOk: async () => {
  94. try {
  95. await deleteSystemSystemMenuCommonlyUsed([record.id]);
  96. createMessage.success('删除成功');
  97. } catch (e) {
  98. createMessage.error('删除失败');
  99. }
  100. },
  101. okText: '确认',
  102. cancelText: '取消',
  103. });
  104. };
  105. onMounted(() => {});
  106. </script>
  107. <style scoped lang="less">
  108. .commonly {
  109. position: relative;
  110. &-group {
  111. font-size: 20px;
  112. font-weight: bold;
  113. color: rgb(11, 11, 11);
  114. margin: 16px 0;
  115. }
  116. &-item {
  117. box-sizing: border-box;
  118. border: 1.6px solid rgb(255, 255, 255);
  119. border-radius: 10px;
  120. box-shadow: 10px 16px 50px 0px rgba(53, 64, 85, 0.05);
  121. background: linear-gradient(180deg, rgb(231, 239, 251), rgb(248, 252, 253) 100%);
  122. border-radius: 8px;
  123. cursor: pointer;
  124. padding: 16px;
  125. position: relative;
  126. &-title {
  127. font-size: 16px;
  128. font-weight: bold;
  129. }
  130. &-desc {
  131. color: rgba(11, 11, 11, 0.6);
  132. }
  133. &-tag {
  134. position: absolute;
  135. right: 0;
  136. top: 0;
  137. border-radius: 0 4px 0 20px;
  138. background-color: rgb(22, 100, 255);
  139. height: 12px;
  140. width: 20px;
  141. display: none;
  142. &-d {
  143. position: absolute;
  144. top: 2px;
  145. left: 10px;
  146. height: 6px;
  147. width: 4px;
  148. border: 1px solid #fff;
  149. border-left: 0;
  150. border-top: 0;
  151. transform-origin: center;
  152. transform: rotate(45deg);
  153. box-sizing: content-box;
  154. }
  155. }
  156. &-active {
  157. .commonly-item-tag {
  158. display: block;
  159. }
  160. }
  161. }
  162. }
  163. </style>