index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="operation-container" @click="playGlobalSound">
  3. <!-- 直接循环 -->
  4. <view class="section" v-for="item in menuData" :key="item.path">
  5. <view class="section-title">{{ item.meta.title }}</view>
  6. <view class="grid-container">
  7. <view
  8. class="grid-item"
  9. v-for="child in item.children"
  10. :style="{ gridColumn: child.query.span ? 'span 2' : 'span 1' }"
  11. :key="child.path"
  12. :class="child.query.type"
  13. @click="handleNavigation(child.path)"
  14. >
  15. {{ formatName(child.meta.title) }}
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 工单操作列表 -->
  20. <view class="section" v-if="workOrderOperations.length > 0">
  21. <view class="section-title">工单</view>
  22. <view class="grid-container">
  23. <view
  24. class="grid-item"
  25. v-for="op in workOrderOperations"
  26. :key="op.path"
  27. @click="handleNavigation(op.path)"
  28. :class="op.type"
  29. >
  30. {{ op.name }}
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup>
  37. import { ref } from "vue";
  38. import { onLoad } from "@dcloudio/uni-app";
  39. //点击全局音效
  40. function playGlobalSound(){
  41. uni.$u.playClickSound()
  42. }
  43. // 菜单数据和加载状态
  44. const menuData = ref([]);
  45. let menuPromise = null;
  46. //获取权限菜单 - 只调用一次
  47. async function getMenuList() {
  48. // 如果已经有数据,直接返回
  49. if (menuData.value && menuData.value.length > 0) {
  50. return menuData.value;
  51. }
  52. // 如果已有一个正在进行的请求,则返回该Promise
  53. if (menuPromise) {
  54. return menuPromise;
  55. }
  56. // 创建新的请求
  57. menuPromise = uni.$u.http
  58. .get("/app/appUser/getRouters")
  59. .then((res) => {
  60. const data = res.data;
  61. menuData.value = data.map((item) => {
  62. item.children = item.children.map((child) => {
  63. child.query = child.query ? JSON.parse(child.query) : {};
  64. return child;
  65. });
  66. return item;
  67. });
  68. return data;
  69. })
  70. .catch((err) => {
  71. // 处理错误情况
  72. console.error("获取菜单数据失败", err);
  73. return [];
  74. })
  75. .finally(() => {
  76. // 请求完成后,重置Promise
  77. menuPromise = null;
  78. });
  79. return menuPromise;
  80. }
  81. //获取按钮权限
  82. function getButtonList() {
  83. uni.$u.http.get("/app/appUser/getInfo").then((res) => {
  84. if (res.code == 200) {
  85. // 保存到本地存储
  86. uni.setStorageSync("buttonList", res.permissions);
  87. }
  88. });
  89. }
  90. //获取音频信息配置
  91. function getAudioConfig() {
  92. uni.$u.http.get("/app/appConf/getAudioConfig").then((res) => {
  93. if (res.code == 200) {
  94. uni.setStorageSync("audioConfig", res.data);
  95. }
  96. });
  97. }
  98. // 页面加载时初始化数据
  99. onLoad(() => {
  100. // 显示加载中提示
  101. uni.showLoading({
  102. title: '加载中...',
  103. mask: true
  104. });
  105. // 初始化菜单和按钮数据
  106. Promise.all([getMenuList(), getButtonList()])
  107. .finally(() => {
  108. // 数据加载完成后,隐藏加载提示
  109. uni.hideLoading();
  110. });
  111. getAudioConfig();
  112. });
  113. const formatName = (name) => {
  114. if (!name) return "";
  115. let result = name;
  116. if (result.includes("\\n\\r")) {
  117. result = result.replace(/\\n\\r/g, "\n");
  118. }
  119. return result;
  120. };
  121. // 工单操作列表
  122. const workOrderOperations = ref([
  123. {
  124. name: "回收工单",
  125. path: "/pages/index/work-order/recycle",
  126. type: "primary",
  127. },
  128. {
  129. name: "卖书工单",
  130. path: "/pages/index/work-order/mall",
  131. type: "warning",
  132. },
  133. ]);
  134. // 页面跳转方法
  135. const handleNavigation = (path) => {
  136. uni.navigateTo({
  137. url: path,
  138. fail: () => {
  139. uni.showToast({
  140. title: "页面跳转失败",
  141. icon: "none",
  142. });
  143. },
  144. });
  145. playGlobalSound();
  146. };
  147. </script>
  148. <style lang="scss" scoped>
  149. .operation-container {
  150. padding: 20rpx;
  151. box-sizing: border-box;
  152. /* #ifdef H5 */
  153. padding-bottom: 100rpx;
  154. /* #endif */
  155. }
  156. .section {
  157. margin-bottom: 30rpx;
  158. background: #ffffff;
  159. border-radius: 16rpx;
  160. padding: 20rpx;
  161. padding-right: 0;
  162. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  163. .section-title {
  164. font-size: 50rpx;
  165. font-weight: 600;
  166. color: #333;
  167. padding: 20rpx;
  168. padding-top: 0;
  169. border-bottom: 2rpx solid #f0f0f0;
  170. margin-bottom: 20rpx;
  171. }
  172. .grid-container {
  173. display: flex;
  174. flex-wrap: wrap;
  175. padding: 10rpx;
  176. .grid-item {
  177. width: calc(50% - 20rpx);
  178. min-height: 148rpx;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. text-align: center;
  183. padding: 20rpx 30rpx;
  184. line-height: 60rpx;
  185. font-size: 50rpx;
  186. border-radius: 12rpx;
  187. color: #ffffff;
  188. transition: all 0.3s;
  189. white-space: pre-wrap;
  190. box-sizing: border-box;
  191. margin-right: 20rpx;
  192. margin-bottom: 20rpx;
  193. &[style*="grid-column: span 2"] {
  194. width: calc(100% - 20rpx);
  195. margin-right: 20rpx;
  196. }
  197. &.primary {
  198. background: linear-gradient(135deg, #4cd964, #3ac555);
  199. &:active {
  200. background: linear-gradient(135deg, #3ac555, #2fb548);
  201. }
  202. }
  203. &.warning {
  204. background: linear-gradient(135deg, #ff9500, #ff8000);
  205. &:active {
  206. background: linear-gradient(135deg, #ff8000, #e67300);
  207. }
  208. }
  209. &:active {
  210. transform: scale(0.98);
  211. }
  212. }
  213. }
  214. }
  215. </style>