index.vue 15 KB

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