index.vue 16 KB

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