index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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="productionSafetyManagement.length > 0" :id="'module-anquan'" :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 productionSafetyManagement" @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 v-if="traceabilityList.length > 0" :id="'module-suyuan'" :data-index="12">
  162. <CellTip title="溯源管理"></CellTip>
  163. <view class="nav">
  164. <view class="nav-content">
  165. <view class="nav-item" v-for="(item, index) in traceabilityList" @click="toNav(item.path)">
  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. </view>
  175. </template>
  176. <script>
  177. import CellTip from "./CellTip.vue";
  178. import {
  179. statistics,
  180. qualityTodoByPda
  181. } from "@/api/myTicket";
  182. export default {
  183. components: {
  184. CellTip,
  185. },
  186. data() {
  187. return {
  188. timer: null,
  189. src1: "https://cdn.uviewui.com/uview/album/1.jpg",
  190. workOrder: {}, // 工单统计数据
  191. qmsList: [],
  192. //生产类
  193. productionList: [],
  194. //仓储管理
  195. warehousingList: [],
  196. //运维类
  197. operationsList: [],
  198. dispatchList: [],
  199. internalManagementList: [],
  200. treeList: [],
  201. saleManageList: [],
  202. // 售后服务
  203. serviceList: [],
  204. // 溯源管理
  205. traceabilityList: [],
  206. // 采购管理
  207. purchaseManageList: [],
  208. pcsList: [],
  209. // 导航相关
  210. moduleNavList: [],
  211. energyManagement:[],
  212. //安全生产
  213. productionSafetyManagement:[],
  214. scrollIntoViewId: "",
  215. currentNavIndex: 0,
  216. moduleObserver: null,
  217. // 顶部固定区域高度(状态栏 + nav-bar + 横向导航)
  218. topNavHeight: 0,
  219. };
  220. },
  221. created() {
  222. this.getTree();
  223. },
  224. onShow() {
  225. // this.getStatistics();
  226. this.$nextTick(() => {
  227. this.calculateTopNavHeight();
  228. });
  229. },
  230. onReady() {
  231. // 页面准备完成后,滚动到第一个模块
  232. this.$nextTick(() => {
  233. if (this.moduleNavList.length > 0) {
  234. this.goToModule(this.moduleNavList[0], 0);
  235. }
  236. });
  237. },
  238. onHide() {
  239. clearTimeout(this.timer);
  240. },
  241. onUnload() {
  242. clearTimeout(this.timer);
  243. },
  244. methods: {
  245. // 计算顶部固定区域高度(动态获取实际高度)
  246. calculateTopNavHeight() {
  247. const query = uni.createSelectorQuery().in(this);
  248. query
  249. .select(".top-nav-wrapper")
  250. .boundingClientRect((rect) => {
  251. if (rect) {
  252. this.topNavHeight = rect.bottom;
  253. }
  254. })
  255. .exec();
  256. },
  257. getStatistics() {
  258. // 获取工单统计数
  259. statistics()
  260. .then((res) => {
  261. this.workOrder = res;
  262. this.operationsList.forEach((item) => {
  263. if (item.name == "保养工单") item.badge = res.maintenanceNum;
  264. if (item.name == "巡点检工单") item.badge = res.patrolInspection;
  265. if (item.name == "维修工单") item.badge = res.repairsNum;
  266. });
  267. })
  268. .finally(() => {
  269. this.timer = setTimeout(() => {
  270. this.getStatistics();
  271. }, 12000);
  272. });
  273. },
  274. getBrages() {
  275. qualityTodoByPda().then((res) => {
  276. console.log(2)
  277. this.qmsList.forEach((item) => {
  278. if (item.name == "质检工单") item.badge = res.workOrderNum;
  279. if (item.name == "我的质检工单")
  280. item.badge = res.myWorkOrderNum;
  281. if (item.name == "我的任务单") item.badge = res.myTaskMonadNum;
  282. if (item.name == "我的受托单")
  283. item.badge = res.myRequestEntrustNum;
  284. });
  285. // this.qmsList = f.children;
  286. });
  287. statistics()
  288. .then((res) => {
  289. this.workOrder = res;
  290. this.operationsList.forEach((item) => {
  291. if (item.name == "保养工单") item.badge = res.maintenanceNum;
  292. if (item.name == "巡点检工单") item.badge = res.patrolInspection;
  293. if (item.name == "维修工单") item.badge = res.repairsNum;
  294. });
  295. })
  296. },
  297. getTree() {
  298. let _list = uni.getStorageSync("treeList");
  299. let list = JSON.parse(_list) || [];
  300. console.log("-----------list--------------");
  301. console.log(list);
  302. // 收集所有异步请求的 Promise
  303. const asyncPromises = [];
  304. if (list[0] && list[0].children.length > 0) {
  305. // console.log(list[0].children, "list[0].children ----");
  306. list[0].children.forEach((f) => {
  307. if (f.path == "productionManage") {
  308. this.productionList = f.children;
  309. } else if (f.path == "operationsList") {
  310. // const promise = statistics().then((res) => {
  311. // console.log(3)
  312. // this.workOrder = res;
  313. // f.children.forEach((item) => {
  314. // if (item.name == "保养工单") item.badge = res.maintenanceNum;
  315. // if (item.name == "巡点检工单")
  316. // item.badge = res.patrolInspection;
  317. // if (item.name == "维修工单") item.badge = res.repairsNum;
  318. // });
  319. this.operationsList = f.children;
  320. // });
  321. // asyncPromises.push(promise);
  322. } else if (f.path == "warehouseManagement") {
  323. this.warehousingList = f.children;
  324. } else if (f.path == "saleManageList") {
  325. this.saleManageList = f.children;
  326. this.saleManageList.forEach((item) => {
  327. item.name = item.name.replace("员工", "");
  328. item.name = item.name.replace("管理员", "");
  329. });
  330. } else if (f.path == "internalManagement") {
  331. // console.log(f, "f");
  332. this.internalManagementList = f.children;
  333. } else if (f.path == "serviceList") {
  334. this.serviceList = f.children;
  335. } else if (f.path == "traceability") {
  336. this.traceabilityList = f.children;
  337. } else if (f.path == "purchasingManage") {
  338. this.purchaseManageList = f.children;
  339. } else if (f.path == "qualityManage") {
  340. // const promise = qualityTodoByPda().then((res) => {
  341. // console.log(2)
  342. // f.children.forEach((item) => {
  343. // if (item.name == "质检工单") item.badge = res.workOrderNum;
  344. // if (item.name == "我的质检工单")
  345. // item.badge = res.myWorkOrderNum;
  346. // if (item.name == "我的任务单") item.badge = res.myTaskMonadNum;
  347. // if (item.name == "我的受托单")
  348. // item.badge = res.myRequestEntrustNum;
  349. // });
  350. this.qmsList = f.children;
  351. // });
  352. // asyncPromises.push(promise);
  353. } else if (f.path == "productionControlManagement") {
  354. this.pcsList = f.children;
  355. } else if (f.path == "dispatchManage") {
  356. this.dispatchList = f.children;
  357. } else if (f.path == 'energyManagement') {
  358. this.energyManagement = f.children
  359. } else if (f.path == 'productionSafetyManagement') {
  360. this.productionSafetyManagement = f.children
  361. }
  362. });
  363. }
  364. // 等待所有异步数据加载完成后再生成导航
  365. // if (asyncPromises.length > 0) {
  366. // // Promise.all(asyncPromises).then(() => {
  367. // console.log(1)
  368. // this.buildNavList();
  369. // // });
  370. // } else {
  371. this.buildNavList();
  372. // }
  373. this.getBrages();
  374. },
  375. // 构建导航列表
  376. buildNavList() {
  377. const navMap = {
  378. internalManagementList: {
  379. name: "协同办公",
  380. id: "xietong"
  381. },
  382. productionList: {
  383. name: "生产管理",
  384. id: "shengchan"
  385. },
  386. operationsList: {
  387. name: "运维管理",
  388. id: "yunwei"
  389. },
  390. serviceList: {
  391. name: "售后服务",
  392. id: "shouhou"
  393. },
  394. warehousingList: {
  395. name: "仓储管理",
  396. id: "cangchu"
  397. },
  398. dispatchList: {
  399. name: "运输管理",
  400. id: "yunshu"
  401. },
  402. saleManageList: {
  403. name: "营销管理",
  404. id: "yingxiao"
  405. },
  406. purchaseManageList: {
  407. name: "采购管理",
  408. id: "caigou"
  409. },
  410. pcsList: {
  411. name: "生产管控",
  412. id: "shengchanguanli"
  413. },
  414. qmsList: {
  415. name: "质量管理",
  416. id: "zhiliang"
  417. },
  418. qmsList: {
  419. name: "能源管理",
  420. id: "module-nengyuan"
  421. },
  422. qmsList: {
  423. name: "生产安全",
  424. id: "module-anquan"
  425. },
  426. traceabilityList: {
  427. name: "溯源管理",
  428. id: "suyuan"
  429. },
  430. };
  431. this.moduleNavList = Object.entries(navMap)
  432. .filter(([key]) => this[key]?.length > 0)
  433. .map(([, value]) => value);
  434. },
  435. // 点击导航跳转 - 使用动态获取的顶部高度进行精确定位
  436. goToModule(item, index) {
  437. this.currentNavIndex = index;
  438. this.scrollIntoViewId = "nav-" + item.id;
  439. setTimeout(() => {
  440. this.scrollIntoViewId = "";
  441. const query = uni.createSelectorQuery().in(this);
  442. query.select("#module-" + item.id).boundingClientRect();
  443. query.select(".top-nav-wrapper").boundingClientRect();
  444. query.selectViewport().scrollOffset();
  445. query.exec((res) => {
  446. if (res[0] && res[1] && res[2]) {
  447. const targetTop = res[0].top;
  448. const fixedBottom = res[1].bottom;
  449. const currentScrollTop = res[2].scrollTop;
  450. const scrollTop = currentScrollTop + targetTop - fixedBottom - 10;
  451. uni.pageScrollTo({
  452. scrollTop: Math.max(0, scrollTop),
  453. duration: 300,
  454. });
  455. }
  456. });
  457. }, 200);
  458. },
  459. // 监听导航滚动
  460. handleNavScroll(e) {
  461. // 可以在这里添加滚动时的逻辑
  462. },
  463. onUnload() {
  464. if (this.moduleObserver) {
  465. this.moduleObserver.disconnect();
  466. }
  467. clearTimeout(this.timer);
  468. },
  469. toNav(url) {
  470. // console.log(url);
  471. uni.navigateTo({
  472. url: url,
  473. });
  474. },
  475. HandlScanCode() {
  476. let _this = this;
  477. uni.scanCode({
  478. success: function(res) {
  479. console.log(res);
  480. // 获取扫描结果中的URL
  481. const scanResult = res.result;
  482. // 检查URL是否包含traceability
  483. if (scanResult && scanResult.includes("/traceability")) {
  484. // 从扫描结果中提取id参数
  485. let id = "";
  486. if (scanResult.includes("id=")) {
  487. // 分割URL获取id参数值
  488. const idPart = scanResult.split("id=")[1];
  489. // 如果id后面还有其他参数,只取到第一个&之前的部分
  490. if (idPart.includes("&")) {
  491. id = idPart.split("&")[0];
  492. } else {
  493. id = idPart;
  494. }
  495. }
  496. // 跳转到溯源页面并传递id
  497. uni.navigateTo({
  498. url: `/pages/traceability/scanCode/index?id=${id}`,
  499. });
  500. return;
  501. } else if(scanResult && scanResult.includes("/pages/warehouse/hwQrcode/index")) {
  502. uni.navigateTo({
  503. url: `${scanResult}`,
  504. });
  505. return
  506. }
  507. _this.scantoRouter(scanResult);
  508. },
  509. });
  510. },
  511. scantoRouter(result) {
  512. uni.navigateTo({
  513. url: `/pages/pda/workOrder/extrusionMolding/index?id=${result}`,
  514. });
  515. },
  516. },
  517. };
  518. </script>
  519. <style lang="scss" scoped>
  520. @import "index.scss";
  521. </style>