index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <view>
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. title="工作台"
  7. right-icon="scan"
  8. @clickRight="HandlScanCode"
  9. ></uni-nav-bar>
  10. <!-- 顶部横向导航 -->
  11. <view class="top-nav-wrapper" v-if="moduleNavList.length > 0">
  12. <scroll-view
  13. class="top-nav"
  14. scroll-x
  15. enable-flex
  16. :scroll-into-view="scrollIntoViewId"
  17. scroll-with-animation
  18. @scroll="handleNavScroll"
  19. >
  20. <view
  21. class="nav-tab"
  22. v-for="(item, index) in moduleNavList"
  23. :key="index"
  24. :id="'nav-' + item.id"
  25. :class="{ active: currentNavIndex === index }"
  26. @click="goToModule(item, index)"
  27. >
  28. {{ item.name }}
  29. </view>
  30. </scroll-view>
  31. </view>
  32. <view class="content-wrapper">
  33. <view
  34. v-if="internalManagementList.length > 0"
  35. :id="'module-xietong'"
  36. :data-index="0"
  37. >
  38. <CellTip title="协同办公"></CellTip>
  39. <view class="nav">
  40. <view class="nav-content">
  41. <view
  42. class="nav-item"
  43. v-for="(item, index) in internalManagementList"
  44. @click="toNav(item.path)"
  45. >
  46. <span :class="'iconfont ' + item.icon"></span>
  47. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  48. <label>{{ item.name }}</label>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view
  54. v-if="productionList.length > 0"
  55. :id="'module-shengchan'"
  56. :data-index="1"
  57. >
  58. <CellTip title="生产管理"></CellTip>
  59. <view class="nav">
  60. <view class="nav-content">
  61. <view
  62. class="nav-item"
  63. v-for="item in productionList"
  64. :key="item.link_url"
  65. @click="toNav(item.path)"
  66. >
  67. <span :class="'iconfont ' + item.icon"></span>
  68. <label>{{ item.title }}</label>
  69. <label>{{ item.num }}</label>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view
  75. v-if="operationsList.length > 0"
  76. :id="'module-yunwei'"
  77. :data-index="2"
  78. >
  79. <CellTip title="运维管理"></CellTip>
  80. <view class="nav">
  81. <view class="nav-content">
  82. <view
  83. class="nav-item"
  84. v-for="(item, index) in operationsList"
  85. @click="toNav(item.path)"
  86. >
  87. <span :class="'iconfont ' + item.icon"></span>
  88. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  89. <label>{{ item.name }}</label>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. <view
  95. v-if="serviceList.length > 0"
  96. :id="'module-shouhou'"
  97. :data-index="3"
  98. >
  99. <CellTip title="售后服务管理"></CellTip>
  100. <view class="nav">
  101. <view class="nav-content">
  102. <view
  103. class="nav-item"
  104. v-for="(item, index) in serviceList"
  105. @click="toNav(item.path)"
  106. >
  107. <span :class="'iconfont ' + item.icon"></span>
  108. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  109. <label>{{ item.name }}</label>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. <view
  115. v-if="warehousingList.length > 0"
  116. :id="'module-cangchu'"
  117. :data-index="4"
  118. >
  119. <CellTip title="仓储管理"></CellTip>
  120. <view class="nav">
  121. <view class="nav-content">
  122. <view
  123. class="nav-item"
  124. v-for="(item, index) in warehousingList"
  125. @click="toNav(item.path)"
  126. >
  127. <span :class="'iconfont ' + item.icon"></span>
  128. <label>{{ item.title }}</label>
  129. </view>
  130. </view>
  131. </view>
  132. </view>
  133. <view
  134. v-if="dispatchList.length > 0"
  135. :id="'module-yunshu'"
  136. :data-index="5"
  137. >
  138. <CellTip title="运输管理"></CellTip>
  139. <view class="nav">
  140. <view class="nav-content">
  141. <view
  142. class="nav-item"
  143. v-for="(item, index) in dispatchList"
  144. @click="toNav(item.path)"
  145. >
  146. <span :class="'iconfont ' + item.icon"></span>
  147. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  148. <label>{{ item.name }}</label>
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. <view
  154. v-if="saleManageList.length > 0"
  155. :id="'module-yingxiao'"
  156. :data-index="6"
  157. >
  158. <CellTip title="营销管理"></CellTip>
  159. <view class="nav">
  160. <view class="nav-content">
  161. <view
  162. class="nav-item"
  163. v-for="(item, index) in saleManageList"
  164. @click="toNav(item.path)"
  165. >
  166. <span :class="'iconfont ' + item.icon"></span>
  167. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  168. <label>{{ item.name }}</label>
  169. </view>
  170. </view>
  171. </view>
  172. </view>
  173. <view
  174. v-if="purchaseManageList.length > 0"
  175. :id="'module-caigou'"
  176. :data-index="7"
  177. >
  178. <CellTip title="采购管理"></CellTip>
  179. <view class="nav">
  180. <view class="nav-content">
  181. <view
  182. class="nav-item"
  183. v-for="(item, index) in purchaseManageList"
  184. @click="toNav(item.path)"
  185. >
  186. <span :class="'iconfont ' + item.icon"></span>
  187. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  188. <label>{{ item.name }}</label>
  189. </view>
  190. </view>
  191. </view>
  192. </view>
  193. <view
  194. v-if="pcsList.length > 0"
  195. :id="'module-shengchanguanli'"
  196. :data-index="8"
  197. >
  198. <CellTip title="生产管控"></CellTip>
  199. <view class="nav">
  200. <view class="nav-content">
  201. <view
  202. class="nav-item"
  203. v-for="(item, index) in pcsList"
  204. @click="toNav(item.path)"
  205. >
  206. <span :class="'iconfont ' + item.icon"></span>
  207. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  208. <label>{{ item.name }}</label>
  209. </view>
  210. </view>
  211. </view>
  212. </view>
  213. <view v-if="qmsList.length > 0" :id="'module-zhiliang'" :data-index="9">
  214. <CellTip title="质量管理"></CellTip>
  215. <view class="nav">
  216. <view class="nav-content">
  217. <view
  218. class="nav-item"
  219. v-for="(item, index) in qmsList"
  220. @click="toNav(item.path)"
  221. >
  222. <span :class="'iconfont ' + item.icon"></span>
  223. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  224. <label>{{ item.name }}</label>
  225. </view>
  226. </view>
  227. </view>
  228. </view>
  229. <view
  230. v-if="traceabilityList.length > 0"
  231. :id="'module-suyuan'"
  232. :data-index="10"
  233. >
  234. <CellTip title="溯源管理"></CellTip>
  235. <view class="nav">
  236. <view class="nav-content">
  237. <view
  238. class="nav-item"
  239. v-for="(item, index) in traceabilityList"
  240. @click="toNav(item.path)"
  241. >
  242. <span :class="'iconfont ' + item.icon"></span>
  243. <i class="badge" v-if="item.badge">{{ item.badge }}</i>
  244. <label>{{ item.name }}</label>
  245. </view>
  246. </view>
  247. </view>
  248. </view>
  249. </view>
  250. </view>
  251. </template>
  252. <script>
  253. import CellTip from "./CellTip.vue";
  254. import { statistics, qualityTodoByPda } from "@/api/myTicket";
  255. export default {
  256. components: {
  257. CellTip,
  258. },
  259. data() {
  260. return {
  261. timer: null,
  262. src1: "https://cdn.uviewui.com/uview/album/1.jpg",
  263. workOrder: {}, // 工单统计数据
  264. qmsList: [],
  265. //生产类
  266. productionList: [],
  267. //仓储管理
  268. warehousingList: [],
  269. //运维类
  270. operationsList: [],
  271. dispatchList: [],
  272. internalManagementList: [],
  273. treeList: [],
  274. saleManageList: [],
  275. // 售后服务
  276. serviceList: [],
  277. // 溯源管理
  278. traceabilityList: [],
  279. // 采购管理
  280. purchaseManageList: [],
  281. pcsList: [],
  282. // 导航相关
  283. moduleNavList: [],
  284. scrollIntoViewId: "",
  285. currentNavIndex: 0,
  286. moduleObserver: null,
  287. // 顶部固定区域高度(状态栏 + nav-bar + 横向导航)
  288. topNavHeight: 0,
  289. };
  290. },
  291. created() {
  292. this.getTree();
  293. },
  294. onShow() {
  295. this.getStatistics();
  296. this.$nextTick(() => {
  297. this.calculateTopNavHeight();
  298. });
  299. },
  300. onReady() {
  301. // 页面准备完成后,滚动到第一个模块
  302. this.$nextTick(() => {
  303. if (this.moduleNavList.length > 0) {
  304. this.goToModule(this.moduleNavList[0], 0);
  305. }
  306. });
  307. },
  308. onHide() {
  309. clearTimeout(this.timer);
  310. },
  311. onUnload() {
  312. clearTimeout(this.timer);
  313. },
  314. methods: {
  315. // 计算顶部固定区域高度(动态获取实际高度)
  316. calculateTopNavHeight() {
  317. const query = uni.createSelectorQuery().in(this);
  318. query
  319. .select(".top-nav-wrapper")
  320. .boundingClientRect((rect) => {
  321. if (rect) {
  322. this.topNavHeight = rect.bottom;
  323. }
  324. })
  325. .exec();
  326. },
  327. getStatistics() {
  328. // 获取工单统计数
  329. statistics()
  330. .then((res) => {
  331. this.workOrder = res;
  332. this.operationsList.forEach((item) => {
  333. if (item.name == "保养工单") item.badge = res.maintenanceNum;
  334. if (item.name == "巡点检工单") item.badge = res.patrolInspection;
  335. if (item.name == "维修工单") item.badge = res.repairsNum;
  336. });
  337. })
  338. .finally(() => {
  339. this.timer = setTimeout(() => {
  340. this.getStatistics();
  341. }, 12000);
  342. });
  343. },
  344. getTree() {
  345. let _list = uni.getStorageSync("treeList");
  346. let list = JSON.parse(_list) || [];
  347. console.log("-----------list--------------");
  348. console.log(list);
  349. // 收集所有异步请求的 Promise
  350. const asyncPromises = [];
  351. if (list[0] && list[0].children.length > 0) {
  352. // console.log(list[0].children, "list[0].children ----");
  353. list[0].children.forEach((f) => {
  354. if (f.path == "productionManage") {
  355. this.productionList = f.children;
  356. } else if (f.path == "operationsList") {
  357. const promise = statistics().then((res) => {
  358. this.workOrder = res;
  359. f.children.forEach((item) => {
  360. if (item.name == "保养工单") item.badge = res.maintenanceNum;
  361. if (item.name == "巡点检工单")
  362. item.badge = res.patrolInspection;
  363. if (item.name == "维修工单") item.badge = res.repairsNum;
  364. });
  365. this.operationsList = f.children;
  366. });
  367. asyncPromises.push(promise);
  368. } else if (f.path == "warehouseManagement") {
  369. this.warehousingList = f.children;
  370. } else if (f.path == "saleManageList") {
  371. this.saleManageList = f.children;
  372. this.saleManageList.forEach((item) => {
  373. item.name = item.name.replace("员工", "");
  374. item.name = item.name.replace("管理员", "");
  375. });
  376. } else if (f.path == "internalManagement") {
  377. // console.log(f, "f");
  378. this.internalManagementList = f.children;
  379. } else if (f.path == "serviceList") {
  380. this.serviceList = f.children;
  381. } else if (f.path == "traceability") {
  382. this.traceabilityList = f.children;
  383. } else if (f.path == "purchasingManage") {
  384. this.purchaseManageList = f.children;
  385. } else if (f.path == "qualityManage") {
  386. const promise = qualityTodoByPda().then((res) => {
  387. f.children.forEach((item) => {
  388. if (item.name == "质检工单") item.badge = res.workOrderNum;
  389. if (item.name == "我的质检工单")
  390. item.badge = res.myWorkOrderNum;
  391. if (item.name == "我的任务单") item.badge = res.myTaskMonadNum;
  392. if (item.name == "我的受托单")
  393. item.badge = res.myRequestEntrustNum;
  394. });
  395. this.qmsList = f.children;
  396. });
  397. asyncPromises.push(promise);
  398. } else if (f.path == "productionControlManagement") {
  399. this.pcsList = f.children;
  400. } else if (f.path == "dispatchManage") {
  401. this.dispatchList = f.children;
  402. }
  403. });
  404. }
  405. // 等待所有异步数据加载完成后再生成导航
  406. if (asyncPromises.length > 0) {
  407. Promise.all(asyncPromises).then(() => {
  408. this.buildNavList();
  409. });
  410. } else {
  411. this.buildNavList();
  412. }
  413. },
  414. // 构建导航列表
  415. buildNavList() {
  416. const navMap = {
  417. internalManagementList: { name: "协同办公", id: "xietong" },
  418. productionList: { name: "生产管理", id: "shengchan" },
  419. operationsList: { name: "运维管理", id: "yunwei" },
  420. serviceList: { name: "售后服务", id: "shouhou" },
  421. warehousingList: { name: "仓储管理", id: "cangchu" },
  422. dispatchList: { name: "运输管理", id: "yunshu" },
  423. saleManageList: { name: "营销管理", id: "yingxiao" },
  424. purchaseManageList: { name: "采购管理", id: "caigou" },
  425. pcsList: { name: "生产管控", id: "shengchanguanli" },
  426. qmsList: { name: "质量管理", id: "zhiliang" },
  427. traceabilityList: { name: "溯源管理", id: "suyuan" },
  428. };
  429. this.moduleNavList = Object.entries(navMap)
  430. .filter(([key]) => this[key]?.length > 0)
  431. .map(([, value]) => value);
  432. },
  433. // 点击导航跳转 - 使用动态获取的顶部高度进行精确定位
  434. goToModule(item, index) {
  435. this.currentNavIndex = index;
  436. this.scrollIntoViewId = "nav-" + item.id;
  437. setTimeout(() => {
  438. this.scrollIntoViewId = "";
  439. const query = uni.createSelectorQuery().in(this);
  440. query.select("#module-" + item.id).boundingClientRect();
  441. query.select(".top-nav-wrapper").boundingClientRect();
  442. query.selectViewport().scrollOffset();
  443. query.exec((res) => {
  444. if (res[0] && res[1] && res[2]) {
  445. const targetTop = res[0].top;
  446. const fixedBottom = res[1].bottom;
  447. const currentScrollTop = res[2].scrollTop;
  448. const scrollTop = currentScrollTop + targetTop - fixedBottom - 10;
  449. uni.pageScrollTo({
  450. scrollTop: Math.max(0, scrollTop),
  451. duration: 300,
  452. });
  453. }
  454. });
  455. }, 200);
  456. },
  457. // 监听导航滚动
  458. handleNavScroll(e) {
  459. // 可以在这里添加滚动时的逻辑
  460. },
  461. onUnload() {
  462. if (this.moduleObserver) {
  463. this.moduleObserver.disconnect();
  464. }
  465. clearTimeout(this.timer);
  466. },
  467. toNav(url) {
  468. // console.log(url);
  469. uni.navigateTo({
  470. url: url,
  471. });
  472. },
  473. HandlScanCode() {
  474. let _this = this;
  475. uni.scanCode({
  476. success: function (res) {
  477. console.log(res);
  478. // 获取扫描结果中的URL
  479. const scanResult = res.result;
  480. // 检查URL是否包含traceability
  481. if (scanResult && scanResult.includes("/traceability")) {
  482. // 从扫描结果中提取id参数
  483. let id = "";
  484. if (scanResult.includes("id=")) {
  485. // 分割URL获取id参数值
  486. const idPart = scanResult.split("id=")[1];
  487. // 如果id后面还有其他参数,只取到第一个&之前的部分
  488. if (idPart.includes("&")) {
  489. id = idPart.split("&")[0];
  490. } else {
  491. id = idPart;
  492. }
  493. }
  494. // 跳转到溯源页面并传递id
  495. uni.navigateTo({
  496. url: `/pages/traceability/scanCode/index?id=${id}`,
  497. });
  498. return;
  499. }
  500. _this.scantoRouter(scanResult);
  501. },
  502. });
  503. },
  504. scantoRouter(result) {
  505. uni.navigateTo({
  506. url: `/pages/pda/workOrder/extrusionMolding/index?id=${result}`,
  507. });
  508. },
  509. },
  510. };
  511. </script>
  512. <style lang="scss" scoped>
  513. @import "index.scss";
  514. </style>