爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
7.1 KiB

  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main$1 = {
  4. name: "AdminTabBar",
  5. data() {
  6. return {
  7. currentPath: "",
  8. tabList: [
  9. {
  10. pagePath: "/pages/component/admin_home",
  11. text: "首页",
  12. icon: "/static/logo.png",
  13. selectedIcon: "/static/111.png"
  14. },
  15. {
  16. pagePath: "/pages/component/role_management",
  17. text: "角色管理",
  18. icon: "/static/logo.png",
  19. selectedIcon: "/static/111.png"
  20. },
  21. {
  22. pagePath: "/pages/component/admin_my",
  23. text: "我的",
  24. icon: "/static/logo.png",
  25. selectedIcon: "/static/111.png"
  26. }
  27. ]
  28. };
  29. },
  30. methods: {
  31. switchTab(path) {
  32. this.currentPath = path;
  33. common_vendor.index.__f__("log", "at wxcomponents/admin-tabr/admin-tabar.vue:54", path);
  34. common_vendor.index.switchTab({
  35. url: path,
  36. fail: () => {
  37. common_vendor.index.navigateTo({
  38. url: path
  39. });
  40. }
  41. });
  42. this.currentPath = path;
  43. },
  44. // 初始化当前页面路径
  45. initCurrentPath() {
  46. const pages = getCurrentPages();
  47. if (pages.length > 0) {
  48. const currentPage = pages[pages.length - 1];
  49. this.currentPath = `/${currentPage.route}`;
  50. }
  51. }
  52. },
  53. mounted() {
  54. this.initCurrentPath();
  55. },
  56. onShow() {
  57. this.initCurrentPath();
  58. }
  59. };
  60. function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
  61. return {
  62. a: common_vendor.f($data.tabList, (item, index, i0) => {
  63. return {
  64. a: $data.currentPath === item.pagePath ? item.selectedIcon : item.icon,
  65. b: common_vendor.t(item.text),
  66. c: index,
  67. d: $data.currentPath === item.pagePath ? 1 : "",
  68. e: common_vendor.o(($event) => $options.switchTab(item.pagePath), index)
  69. };
  70. })
  71. };
  72. }
  73. const AdminTabBar = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-74645b33"]]);
  74. const _sfc_main = {
  75. name: "UserTabBar",
  76. data() {
  77. return {
  78. currentTab: "/pages/component/home",
  79. tabList: [
  80. {
  81. pagePath: "/pages/component/home",
  82. text: "首页",
  83. iconPath: "/static/logo.png",
  84. selectedIconPath: "/static/logo.png"
  85. },
  86. {
  87. pagePath: "/pages/component/recycle",
  88. text: "回收",
  89. iconPath: "/static/logo.png",
  90. selectedIconPath: "/static/logo.png"
  91. },
  92. {
  93. pagePath: "/pages/component/my",
  94. text: "我的",
  95. iconPath: "/static/logo.png",
  96. selectedIconPath: "/static/logo.png"
  97. }
  98. ]
  99. };
  100. },
  101. methods: {
  102. switchTab(path) {
  103. if (this.currentTab === path)
  104. return;
  105. const oldPath = this.currentTab;
  106. this.currentTab = path;
  107. common_vendor.index.switchTab({
  108. url: path,
  109. success: () => {
  110. common_vendor.index.__f__("log", "at wxcomponents/user-tabar/user-tabar.vue:60", "切换成功");
  111. },
  112. fail: () => {
  113. common_vendor.index.navigateTo({
  114. url: path,
  115. success: () => {
  116. common_vendor.index.__f__("log", "at wxcomponents/user-tabar/user-tabar.vue:67", "导航成功");
  117. },
  118. fail: () => {
  119. this.currentTab = oldPath;
  120. common_vendor.index.__f__("log", "at wxcomponents/user-tabar/user-tabar.vue:72", "切换失败");
  121. }
  122. });
  123. }
  124. });
  125. },
  126. updateCurrentTab() {
  127. const pages = getCurrentPages();
  128. if (pages.length > 0) {
  129. const currentPage = pages[pages.length - 1];
  130. const newPath = "/" + currentPage.route;
  131. if (this.currentTab !== newPath) {
  132. this.currentTab = newPath;
  133. }
  134. }
  135. }
  136. },
  137. created() {
  138. this.updateCurrentTab();
  139. },
  140. onShow() {
  141. this.updateCurrentTab();
  142. },
  143. onLoad() {
  144. this.updateCurrentTab();
  145. }
  146. };
  147. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  148. return {
  149. a: common_vendor.f($data.tabList, (item, index, i0) => {
  150. return {
  151. a: $data.currentTab === item.pagePath ? item.selectedIconPath : item.iconPath,
  152. b: common_vendor.t(item.text),
  153. c: index,
  154. d: $data.currentTab === item.pagePath ? 1 : "",
  155. e: common_vendor.o(($event) => $options.switchTab(item.pagePath), index)
  156. };
  157. })
  158. };
  159. }
  160. const UserTabBar = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d2bf226b"]]);
  161. const tabBarMixin = {
  162. components: {
  163. AdminTabBar,
  164. UserTabBar
  165. },
  166. data() {
  167. return {
  168. userRole: "",
  169. isTabBarVisible: true,
  170. currentPath: "",
  171. tabBarIndex: 0
  172. };
  173. },
  174. computed: {
  175. isAdmin() {
  176. return this.userRole === "admin";
  177. },
  178. shouldShowTabBar() {
  179. const tabBarPages = [
  180. "/pages/component/admin_home",
  181. "/pages/component/role_management",
  182. "/pages/component/admin_my"
  183. ];
  184. return tabBarPages.includes(this.currentPath);
  185. }
  186. },
  187. methods: {
  188. async checkUserRole() {
  189. try {
  190. const userInfo = common_vendor.index.getStorageSync("userInfo");
  191. if (userInfo && userInfo.role) {
  192. this.userRole = userInfo.role;
  193. } else {
  194. this.userRole = "user";
  195. }
  196. } catch (e) {
  197. common_vendor.index.__f__("error", "at pages/mixins/tabBarMixin.js:40", "获取用户角色失败:", e);
  198. this.userRole = "user";
  199. }
  200. },
  201. updateCurrentPath() {
  202. const pages = getCurrentPages();
  203. if (pages.length > 0) {
  204. const currentPage = pages[pages.length - 1];
  205. common_vendor.index.__f__("log", "at pages/mixins/tabBarMixin.js:48", currentPage, "text");
  206. this.currentPath = "/" + currentPage.route;
  207. this.isTabBarVisible = this.shouldShowTabBar;
  208. common_vendor.index.__f__("log", "at pages/mixins/tabBarMixin.js:51", "当前页面路径:", this.currentPath);
  209. }
  210. },
  211. hideTabBar() {
  212. this.isTabBarVisible = false;
  213. },
  214. showTabBar() {
  215. this.isTabBarVisible = this.shouldShowTabBar;
  216. },
  217. switchTab(index) {
  218. const routes = ["pages/index/index", "pages/role-management/role-management", "pages/my/my"];
  219. if (!this.isAdmin && index === 1) {
  220. common_vendor.index.showToast({
  221. title: "无权限访问",
  222. icon: "none"
  223. });
  224. return;
  225. }
  226. this.tabBarIndex = index;
  227. common_vendor.index.switchTab({
  228. url: "/" + routes[index]
  229. });
  230. }
  231. },
  232. onShow() {
  233. this.checkUserRole();
  234. this.updateCurrentPath();
  235. const pages = getCurrentPages();
  236. const currentPage = pages[pages.length - 1];
  237. const route = currentPage.route;
  238. const routes = ["pages/index/index", "pages/role-management/role-management", "pages/my/my"];
  239. this.tabBarIndex = routes.findIndex((r) => r === route);
  240. },
  241. onLoad() {
  242. this.checkUserRole();
  243. this.updateCurrentPath();
  244. },
  245. mounted() {
  246. this.checkUserRole();
  247. this.updateCurrentPath();
  248. }
  249. };
  250. exports.tabBarMixin = tabBarMixin;
  251. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/mixins/tabBarMixin.js.map