Entrance.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="home-entrance-container">
  3. <el-card shadow="never" class="right-entrance w100" v-loading="state.entranceLoading">
  4. <p class="right-entrance-title">
  5. 常用入口
  6. <el-button @click="openDialog" link><SvgIcon name="ele-Setting" class="mr1" />自定义 </el-button>
  7. </p>
  8. <template v-if="state.entranceArray.length">
  9. <el-scrollbar class="h100">
  10. <ul class="right-entrance-list">
  11. <li
  12. class="right-entrance-list-item"
  13. v-for="item in state.entranceArray"
  14. :title="item.pageName"
  15. :key="item.id"
  16. :data-id="item.id"
  17. @click="goLink(item)"
  18. >
  19. <SvgIcon :name="item.icon" size="28px" class="my-handle" />
  20. <p class="text-no-wrap">{{ item.pageName }}</p>
  21. </li>
  22. </ul>
  23. </el-scrollbar>
  24. </template>
  25. <el-empty :image-size="100" v-else />
  26. </el-card>
  27. <el-dialog v-model="state.dialogVisible" draggable title="常用入口设置" @opened="opened">
  28. <div class="entrance-list">
  29. <p class="entrance-list-title">
  30. 首页入口 <span v-if="state.entranceList.length">({{ state.entranceList.length }})</span>
  31. <el-button link type="primary" class="ml10" @click="clearEntrance" title="清空首页入口" v-if="state.entranceList.length">
  32. <SvgIcon name="ele-Delete" class="mr3"></SvgIcon>清空</el-button
  33. >
  34. </p>
  35. <div class="mb20" v-loading="state.loading">
  36. <div class="entrance-list-box" v-show="state.entranceList.length">
  37. <div class="entrance-list-box-item" :title="item.pageName" v-for="item in state.entranceList" :key="item.id" :data-id="item.id">
  38. <SvgIcon :name="item.icon" class="my-handle" size="28px" />
  39. <p class="entrance-list-box-item-name text-no-wrap">{{ item.pageName }}</p>
  40. <SvgIcon name="ele-RemoveFilled" class="plus-icon location" color="#ccc" size="20px" @click="removeOne(item)" />
  41. </div>
  42. </div>
  43. <el-empty v-show="!state.entranceList.length" :image-size="120" />
  44. </div>
  45. </div>
  46. <div class="entrance-select">
  47. <p class="entrance-select-title">
  48. <span class="entrance-select-title-name"
  49. >系统功能 <span v-if="state.entranceSelect.length">({{ state.entranceSelect.length }})</span>
  50. <el-button link type="primary" @click="selectAll" class="ml10" v-if="state.entranceSelect.length" title="全选到首页入口">
  51. <SvgIcon name="ele-CircleCheck" class="mr3"></SvgIcon>全选</el-button
  52. ></span
  53. >
  54. <el-input v-model="state.searchKey" placeholder="请填写关键字" class="input" @keyup.enter="getEntranceSelect">
  55. <template #prefix>
  56. <SvgIcon name="ele-Search" />
  57. </template>
  58. <template #suffix>
  59. <el-button type="primary" size="small" round @click="getEntranceSelect">搜索</el-button>
  60. </template>
  61. </el-input>
  62. </p>
  63. <div class="mb20" v-loading="state.selectLoading">
  64. <template v-if="state.entranceSelect.length">
  65. <ul class="entrance-list-box">
  66. <li class="entrance-list-box-item" v-for="item in state.entranceSelect" :key="item.id" :title="item.pageName">
  67. <SvgIcon :name="item.icon" size="28px" class="entrance-list-box-item-icon" />
  68. <p class="entrance-list-box-item-name text-no-wrap">{{ item.pageName }}</p>
  69. <SvgIcon
  70. name="ele-CirclePlusFilled"
  71. class="remove-icon location"
  72. color="var(--el-color-primary)"
  73. size="20px"
  74. @click="plusOne(item)"
  75. />
  76. </li>
  77. </ul>
  78. </template>
  79. <el-empty v-else :image-size="100" />
  80. </div>
  81. </div>
  82. <template #footer>
  83. <span class="dialog-footer">
  84. <el-button @click="state.dialogVisible = false" class="default-button">取 消</el-button>
  85. <el-button type="primary" @click="onSubmit">保 存</el-button>
  86. </span>
  87. </template>
  88. </el-dialog>
  89. </div>
  90. </template>
  91. <script lang="ts" setup name="homeEntrance">
  92. import { onMounted, reactive } from 'vue';
  93. import { ElMessage } from 'element-plus';
  94. import { useRouter } from 'vue-router';
  95. import { geFastMenu, fastMenu, setFastMenu } from '@/api/home';
  96. import Sortable from 'sortablejs';
  97. const state = reactive<any>({
  98. dialogVisible: false,
  99. searchKey: '',
  100. entranceList: [],
  101. sortEntranceList: [],
  102. entranceSelect: [],
  103. loading: false,
  104. selectLoading: false,
  105. entranceArray: <EmptyArrayType>[], // 常用入口
  106. entranceLoading: false, //入口
  107. sortable: '',
  108. });
  109. // 跳转到
  110. const router = useRouter();
  111. const goLink = (item: any) => {
  112. router.push({
  113. path: item.path,
  114. });
  115. };
  116. //获取入口设置
  117. const getMyEntrance = () => {
  118. state.entranceLoading = true;
  119. geFastMenu()
  120. .then((res: any) => {
  121. state.entranceArray = res?.result ?? [];
  122. state.entranceLoading = false;
  123. })
  124. .catch(() => {
  125. state.entranceLoading = false;
  126. });
  127. };
  128. // 打开弹窗
  129. const openDialog = () => {
  130. state.dialogVisible = true;
  131. getEntrance();
  132. getEntranceSelect();
  133. };
  134. // 关闭弹窗
  135. const closeDialog = () => {
  136. state.dialogVisible = false;
  137. };
  138. // 获取我的入口
  139. const getEntrance = () => {
  140. state.loading = true;
  141. geFastMenu()
  142. .then((res: any) => {
  143. state.entranceList = res?.result ?? [];
  144. state.loading = false;
  145. })
  146. .catch(() => {
  147. state.loading = false;
  148. });
  149. };
  150. // 获取可选入口
  151. const getEntranceSelect = () => {
  152. state.selectLoading = true;
  153. fastMenu({})
  154. .then((res: any) => {
  155. state.entranceSelect = res?.result ?? [];
  156. if (state.searchKey) {
  157. state.entranceSelect = state.entranceSelect.filter((i: any) => i.pageName.includes(state.searchKey));
  158. if (state.entranceList.length) {
  159. state.entranceSelect = state.entranceSelect.filter((i: any) => !state.entranceList.some((j: any) => j.id === i.id));
  160. }
  161. } else {
  162. if (state.entranceList.length) {
  163. state.entranceSelect = state.entranceSelect.filter((i: any) => !state.entranceList.some((j: any) => j.id === i.id));
  164. }
  165. }
  166. setTimeout(() => {
  167. state.selectLoading = false;
  168. }, 300);
  169. })
  170. .catch(() => {
  171. state.selectLoading = false;
  172. });
  173. };
  174. // 移除
  175. const removeOne = (val: any) => {
  176. state.entranceList = state.entranceList.filter((i: any) => i.id !== val.id);
  177. state.entranceSelect.unshift(val);
  178. };
  179. // 新增
  180. const plusOne = (val: any) => {
  181. state.entranceList.push(val);
  182. state.entranceSelect = state.entranceSelect.filter((i: any) => i.id !== val.id);
  183. };
  184. // 清空
  185. const clearEntrance = () => {
  186. state.entranceSelect = [...state.entranceList, ...state.entranceSelect];
  187. state.entranceList = [];
  188. };
  189. // 全选
  190. const selectAll = () => {
  191. state.entranceList = [...state.entranceList, ...state.entranceSelect];
  192. state.entranceSelect = [];
  193. };
  194. // 设置 tagsView 可以进行拖拽
  195. const initSortable = async () => {
  196. const el = <HTMLElement>document.querySelector('.entrance-list-box');
  197. if (!el) return false;
  198. state.sortable.el && state.sortable.destroy();
  199. state.sortable = Sortable.create(el, {
  200. animation: 300,
  201. dataIdAttr: 'data-id',
  202. onEnd: () => {
  203. const sortEndList: any[] = [];
  204. state.sortable.toArray().map((val: string) => {
  205. state.entranceList.map((v: any) => {
  206. if (v.id === val) sortEndList.push({ ...v });
  207. });
  208. addBrowserSetSession(sortEndList);
  209. });
  210. },
  211. });
  212. };
  213. // 保存
  214. const addBrowserSetSession = (value: Array<object>) => {
  215. state.sortEntranceList = value;
  216. };
  217. const opened = () => {
  218. initSortable();
  219. };
  220. // 保存
  221. const onSubmit = async () => {
  222. try {
  223. let req = state.sortEntranceList.length
  224. ? state.sortEntranceList.map((item: any) => item.permissionCode)
  225. : state.entranceList.map((item: any) => item.permissionCode);
  226. await setFastMenu({ fastMenuArr: req });
  227. ElMessage.success('操作成功');
  228. getMyEntrance();
  229. } catch {
  230. // 处理错误
  231. state.dialogVisible = false;
  232. } finally {
  233. state.dialogVisible = false;
  234. }
  235. };
  236. onMounted(() => {
  237. getMyEntrance();
  238. });
  239. </script>
  240. <style lang="scss" scoped>
  241. .home-entrance-container {
  242. .right-entrance {
  243. &-title {
  244. font-size: var(--el-font-size-medium);
  245. display: flex;
  246. align-items: center;
  247. justify-content: space-between;
  248. padding-bottom: 20px;
  249. font-weight: 600;
  250. span {
  251. font-size: 14px;
  252. display: flex;
  253. align-items: center;
  254. color: var(--el-text-color-regular);
  255. cursor: pointer;
  256. font-weight: normal;
  257. }
  258. }
  259. &-list {
  260. display: grid;
  261. grid-template-columns: repeat(auto-fill, 90px);
  262. justify-content: space-between;
  263. grid-gap: 8px;
  264. max-height: 250px;
  265. overflow: auto;
  266. &-item {
  267. background: var(--hotline-bg-main-color);
  268. border-radius: 8px;
  269. text-align: center;
  270. width: 90px;
  271. height: 90px;
  272. cursor: pointer;
  273. color: var(--el-text-color-regular);
  274. user-select: none;
  275. padding: 10px 5px;
  276. .my-handle {
  277. display: inline-block;
  278. width: 30px;
  279. height: 30px;
  280. margin-top: 10px;
  281. margin-bottom: 5px;
  282. }
  283. &:hover {
  284. color: var(--el-color-primary);
  285. background-color: var(--el-color-primary-light-8);
  286. }
  287. }
  288. }
  289. }
  290. .entrance-list {
  291. color: var(--hotline-color-text-main);
  292. &-title {
  293. padding-bottom: 20px;
  294. font-size: var(--el-font-size-medium);
  295. }
  296. &-box {
  297. display: grid;
  298. justify-content: space-between;
  299. grid-template-columns: repeat(auto-fill, 100px);
  300. grid-gap: 10px;
  301. margin-bottom: 20px;
  302. &-item {
  303. background: #f0f4ff;
  304. border-radius: 8px;
  305. text-align: center;
  306. padding: 10px 5px;
  307. width: 100px;
  308. height: 100px;
  309. color: var(--el-text-color-regular);
  310. position: relative;
  311. user-select: none;
  312. &-icon {
  313. display: inline-block;
  314. width: 30px;
  315. height: 30px;
  316. margin-bottom: 15px;
  317. margin-top: 5px;
  318. }
  319. .my-handle {
  320. display: inline-block;
  321. width: 30px;
  322. height: 30px;
  323. margin-bottom: 15px;
  324. cursor: grab;
  325. margin-top: 5px;
  326. }
  327. .location {
  328. position: absolute;
  329. top: -5px;
  330. right: -5px;
  331. cursor: pointer;
  332. }
  333. }
  334. }
  335. }
  336. .entrance-select {
  337. color: var(--hotline-color-text-main);
  338. &-title {
  339. padding-bottom: 20px;
  340. font-size: var(--el-font-size-medium);
  341. &-name {
  342. display: inline-block;
  343. min-width: 80px;
  344. margin-right: 40px;
  345. }
  346. .input {
  347. max-width: 350px;
  348. :deep(.el-input__wrapper) {
  349. border-radius: 40px;
  350. }
  351. }
  352. }
  353. }
  354. }
  355. </style>