quickEntrance.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="w-full h-full flex flex-col">
  3. <div class="bg-[#f4f5fa] text-center componentTitle">快捷新建设置</div>
  4. <div class="smallFontTitle">快捷新建</div>
  5. <div class="module">
  6. <div class="module-item" v-for="(item, index) in selectList" :key="index">
  7. <div class="module-img"><img :src="getRouterImg(item.path)" alt=""></div>
  8. <div class="module-text">建{{ item.name }}</div>
  9. <div class="absolute top-0 right-0" @click="operationEntrance(index, 'delete')">
  10. <van-icon name="clear" color="#aaaaaa" size="18" />
  11. </div>
  12. </div>
  13. </div>
  14. <div class="smallFontTitle">全部</div>
  15. <div class="flex-1 overflow-y-auto">
  16. <div class="module">
  17. <div class="module-item" v-for="(item, index) in allList">
  18. <div class="module-img"><img :src="getRouterImg(item.path)" alt=""></div>
  19. <div class="module-text">建{{ item.name }}</div>
  20. <div class="absolute top-0 right-0" v-if="selectList.length < 4" @click="operationEntrance(index, 'add')">
  21. <van-icon name="add" color="#1a6afb" size="18" />
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <!-- 确定按钮 -->
  27. <van-button type="primary" class="confirmToSave" :disabled="!selectList.length" @click="saveConfiguration" loading-text="保存中..." :loading="loading">保存</van-button>
  28. </div>
  29. </template>
  30. <script setup>
  31. import { ref, defineProps, defineEmits, watch } from "vue";
  32. import requests from "@common/requests"
  33. import { SAVE_FAST_ACCESS_LIST } from "@hooks/useApi";
  34. import useToast from "@hooks/useToast"
  35. import { routingInfos, getRouterImg } from "@utility/generalVariables.js";
  36. const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
  37. const emit = defineEmits();
  38. const props = defineProps({
  39. allModulesList: Array,
  40. selectModule: Array
  41. });
  42. const selectList = ref([])
  43. const allList = ref([])
  44. const loading = ref(false)
  45. watch(() => props.selectModule, (newValue, oldValue) => {
  46. processingData()
  47. }, { immediate: true });
  48. function saveConfiguration() {
  49. loading.value = true
  50. const list = selectList.value.map(item => {
  51. return {
  52. id: item.id,
  53. name: item.name,
  54. router: item.path
  55. }
  56. })
  57. requests.post(SAVE_FAST_ACCESS_LIST, { jsonstr: JSON.stringify(list) }).then(() => {
  58. toastSuccess('保存成功')
  59. emit('save-value')
  60. }).finally(() => {
  61. loading.value = false
  62. })
  63. }
  64. function operationEntrance(index, type) {
  65. if(type == 'add') {
  66. selectList.value.push(allList.value[index])
  67. } else {
  68. selectList.value.splice(index, 1)
  69. }
  70. allList.value = props.allModulesList.filter(item => !selectList.value.some(arrItem => arrItem.path === item.path))
  71. }
  72. function processingData() {
  73. allList.value = props.allModulesList.filter(item => !props.selectModule.some(arrItem => arrItem.path === item.path))
  74. selectList.value = props.selectModule
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .componentTitle {
  79. font-size: 20px;
  80. line-height: 54px;
  81. }
  82. .smallFontTitle {
  83. font-size: 16px;
  84. font-weight: bold;
  85. color: #202d45;
  86. padding: 15px 20px;
  87. }
  88. .module {
  89. padding: 0 20px;
  90. display: flex;
  91. flex-wrap: wrap;
  92. position: relative;
  93. .module-item {
  94. width: 22.5%;
  95. padding: 10px 0;
  96. background: #fff;
  97. box-shadow: 0px 2px 8px 0px #e4e4e4;
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. border-radius: 6px;
  102. margin-right: 3%;
  103. margin-bottom: 8px;
  104. position: relative;
  105. &:nth-child(4n) {
  106. margin-right: 0;
  107. }
  108. .module-img {
  109. width: 30px;
  110. height: 30px;
  111. margin-bottom: 10px;
  112. }
  113. }
  114. }
  115. .confirmToSave {
  116. margin: 10px 20px;
  117. }
  118. </style>