Entrance.vue 9.7 KB

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