DownloadList.uvue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <view class="container">
  3. <!-- 搜索栏 -->
  4. <view class="info-row btn-panel search-bar">
  5. <view class="search-input">
  6. <input type="text" v-model="productNo" placeholder="请输入工序码"/>
  7. </view>
  8. <view class="scan-btn" @click="scanQRCode">
  9. <uni-icons type="scan" size="32" color="#00aaff"></uni-icons>
  10. </view>
  11. </view>
  12. <!-- 按钮面板 -->
  13. <view class="info-row btn-panel">
  14. <button class="btn btn-first" @click="download">
  15. 下载数据
  16. </button>
  17. <button class="btn btn-second" @click="search">
  18. 搜索
  19. </button>
  20. </view>
  21. <!-- 列表内容 -->
  22. <!-- #ifdef APP -->
  23. <scroll-view style="flex:1">
  24. <!-- #endif -->
  25. <view class="download-card" v-for="(item, index) in downloads" :key="index" >
  26. <view @click="enterItem(item.pdid)">
  27. <view class="info-row">
  28. <text class="label">工序:</text>
  29. <text class="value">{{ item.gxno }}</text>
  30. </view>
  31. <view class="info-row">
  32. <text class="label">路卡号:</text>
  33. <text class="value">{{ item.cardno }}</text>
  34. </view>
  35. <view class="info-row">
  36. <text class="label">工作令:</text>
  37. <text class="value">{{ item.workorder }}</text>
  38. </view>
  39. <view class="info-row">
  40. <text class="label">产品名称:</text>
  41. <text class="value">{{ item.invname }}</text>
  42. </view>
  43. <view class="info-row">
  44. <text class="label">图号:</text>
  45. <text class="value">{{ item.graphid }}</text>
  46. </view>
  47. <view class="info-row">
  48. <text class="label">工艺编号:</text>
  49. <text class="value">{{ item.processno }}</text>
  50. </view>
  51. <view class="info-row">
  52. <text class="label">版本号:</text>
  53. <text class="value">{{ item.ver }}</text>
  54. </view>
  55. <view class="info-row">
  56. <text class="label">最近更新时间:</text>
  57. <text class="value">{{ item.lastupdatetime }}</text>
  58. </view>
  59. <view class="info-row">
  60. <text class="label">进度:</text>
  61. <text class="process-value" :class="{
  62. 'bg-green': ( item.photoStatus + item.keyStatus + item.recordStatus) == (item.photoTotal + item.keyTotal + item.recordTotal),
  63. 'bg-yellow': ( item.photoStatus + item.keyStatus + item.recordStatus) < (item.photoTotal + item.keyTotal + item.recordTotal),
  64. 'bg-black': ( item.photoStatus + item.keyStatus + item.recordStatus) == 0
  65. }"> {{ (item.photoStatus + item.keyStatus + item.recordStatus) }} / {{(item.photoTotal + item.keyTotal + item.recordTotal)}} </text>
  66. </view>
  67. <view class="info-row">
  68. <text class="label">上传时间:</text>
  69. <text class="value">{{ item.uploadtime }}</text>
  70. </view>
  71. </view>
  72. <view class="info-row">
  73. <button class="btn btn-second" @click="upload(item)">
  74. 上传数据
  75. </button>
  76. </view>
  77. </view>
  78. <!-- #ifdef APP -->
  79. </scroll-view>
  80. <!-- #endif -->
  81. </view>
  82. </template>
  83. <script setup>
  84. import { ref, reactive } from 'vue'
  85. import { getTaskInfoList } from '@/api/work';
  86. import { downloadDataFromAPI, uploadDataToAPI } from '@/utils/qcDataProcessor.uts';
  87. // 产品号输入框数据
  88. const productNo = ref('PI02297172');
  89. const backPressOptions = reactive({
  90. from: 'backbutton'
  91. } as OnBackPressOptions)
  92. onBackPress((options : OnBackPressOptions) : boolean | null => {
  93. // 使用reLaunch代替switchTab,避免多层跳转时的闪回问题
  94. // reLaunch会关闭所有页面并打开到目标页面,适合需要完全重置导航栈的场景
  95. uni.reLaunch({
  96. url: `/pages/work/index`,
  97. })
  98. // 返回true表示拦截默认返回行为
  99. return true
  100. })
  101. type Task = {
  102. pdid : number,
  103. gxpk : string,
  104. cardno : string,
  105. productcode : string,
  106. model : string,
  107. workorder : string,
  108. invname : string,
  109. graphid : string,
  110. processno : string,
  111. gxno : string,
  112. ver : string,
  113. lastupdatetime : string,
  114. photoStatus : number,
  115. keyStatus : number,
  116. recordStatus : number,
  117. photoTotal: number,
  118. keyTotal: number,
  119. recordTotal: number,
  120. uploadFlag: number,
  121. uploadtime : string,
  122. }
  123. var initDownloads = [] as Task[]
  124. var downloads = ref<Task[]>([]);
  125. const map = ref(new Map<number, string>([[1, '未执行'], [2, '执行中'], [3, '执行完'], [4, '有错误']]))
  126. // #ifdef APP-ANDROID
  127. getTaskInfoList('', null).then((res : UTSJSONObject) => {
  128. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  129. if (dataList != null && dataList.length > 0) {
  130. dataList.forEach(item => {
  131. if (item != null) {
  132. let download = JSON.parse<Task>(item.toJSONString());
  133. if (download != null) {
  134. initDownloads.push(download)
  135. }
  136. }
  137. });
  138. }
  139. downloads.value = initDownloads
  140. })
  141. // #endif
  142. // #ifdef H5
  143. downloads = [{
  144. pdid: 1,
  145. workorder: "632-P-01",
  146. invname: "箱间段",
  147. productno: "1CFA1040-00#S",
  148. graphid: '',
  149. ver: '',
  150. cardno: "LK20230707070012",
  151. processno: "Pb/XXX-E11",
  152. updatetime: "2025-06-23",
  153. createtime : "2025-06-23",
  154. totalRecord : 3,
  155. statusRecordCount : 3,
  156. uploadFlag: 1,
  157. status: 3
  158. }, {
  159. pdid: 2,
  160. workorder: "712-SY-10-6",
  161. invname: "级间架",
  162. productno: "1XA1020-00A",
  163. graphid: '',
  164. ver: '',
  165. cardno: "LK20250215003",
  166. processno: "Pb/XXX-E11",
  167. createtime : "2025-06-23",
  168. updatetime: "2025-08-25",
  169. totalRecord : 4,
  170. statusRecordCount : 2,
  171. uploadFlag: 1,
  172. status: 2
  173. }, {
  174. pdid: 3,
  175. workorder: "712-SY-10-6",
  176. invname: "级间架",
  177. productno: "1XA1020-00A",
  178. graphid: '',
  179. ver: '',
  180. cardno: "LK20250215003",
  181. processno: "Pb/XXX-E11",
  182. createtime : "2025-06-23",
  183. updatetime: "2025-08-25",
  184. totalRecord : 4,
  185. statusRecordCount : 0,
  186. uploadFlag: 1,
  187. status: 1
  188. }] as Task[];
  189. // #endif
  190. const download = async (e : any) => {
  191. console.log("开始下载...")
  192. // 调用数据处理工具中的方法下载数据
  193. if(productNo.value == null || productNo.value == '') {
  194. uni.showToast({
  195. title: '请先扫描或者输入工序码',
  196. icon: 'error'
  197. });
  198. return
  199. }
  200. await downloadDataFromAPI(productNo.value, () => {
  201. // 回调函数中执行刷新,确保数据都保存好,进度条跑完
  202. uni.reLaunch({ url: '/pages/work/download/DownloadList' })
  203. }).then((res) => {
  204. // 移除这里的刷新逻辑,避免过早刷新
  205. })
  206. }
  207. const upload = async (e : Task) => {
  208. if((e.photoStatus + e.keyStatus + e.recordStatus ) != (e.photoTotal + e.keyTotal + e.recordTotal)) {
  209. uni.showToast({
  210. title: '当前任务还未完成!',
  211. icon: 'error'
  212. });
  213. return
  214. }
  215. console.log("开始上传...")
  216. uploadDataToAPI(e.gxpk, () => {
  217. }).then((res) => {
  218. // 移除这里的刷新逻辑,避免过早刷新
  219. uni.reLaunch({ url: '/pages/work/download/DownloadList' })
  220. })
  221. }
  222. const enterItem = (id : number) => {
  223. uni.navigateTo({
  224. url: `/pages/work/download/DownloadDetail?id=${id}`
  225. });
  226. }
  227. // 扫描二维码功能
  228. const scanQRCode = () => {
  229. uni.scanCode({
  230. success: (res) => {
  231. // 扫描成功,将结果填充到输入框
  232. productNo.value = res.result;
  233. console.log('扫描结果:', res.result);
  234. },
  235. fail: (err) => {
  236. console.error('扫描失败:', err);
  237. uni.showToast({
  238. title: '扫描失败,请重试',
  239. icon: 'error'
  240. });
  241. }
  242. });
  243. }
  244. const search = async () => {
  245. // 检查productNo是否为空
  246. if (productNo.value == null || productNo.value.trim() == '') {
  247. uni.showToast({
  248. title: '请输入产品号',
  249. icon: 'error'
  250. });
  251. return;
  252. }
  253. // 显示加载提示
  254. uni.showLoading({
  255. title: '搜索中...'
  256. });
  257. try {
  258. // 使用getRecordInfoList函数并传入productNo.value作为第一个参数
  259. let query = `m.gxpk like '%${productNo.value}%'`
  260. const res = await getTaskInfoList(query, null);
  261. console.log('搜索结果:', res);
  262. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
  263. let searchResults = [] as Task[];
  264. if (dataList != null && dataList.length > 0) {
  265. dataList.forEach(item => {
  266. if (item != null) {
  267. try {
  268. let download = JSON.parse<Task>(item.toJSONString());
  269. if (download != null) {
  270. searchResults.push(download);
  271. }
  272. } catch (e) {
  273. console.error('解析数据失败:', e);
  274. }
  275. }
  276. });
  277. }
  278. // 更新downloads数组,显示搜索结果
  279. downloads.value = searchResults;
  280. // 如果没有搜索到结果,显示提示
  281. if (searchResults.length === 0) {
  282. uni.showToast({
  283. title: '未找到相关数据',
  284. icon: 'none'
  285. });
  286. }
  287. } catch (error) {
  288. console.error('搜索失败:', error);
  289. uni.showToast({
  290. title: '搜索失败,请重试',
  291. icon: 'error'
  292. });
  293. } finally {
  294. // 隐藏加载提示
  295. uni.hideLoading();
  296. }
  297. }
  298. defineExpose({
  299. backPressOptions
  300. })
  301. </script>
  302. <style scope>
  303. .container {
  304. padding: 24rpx;
  305. background-color: #f0f4f8;
  306. flex: 1;
  307. display: flex;
  308. flex-direction: column;
  309. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  310. /* #ifndef APP-ANDROID */
  311. min-height: 100vh;
  312. /* #endif */
  313. height: 120rpx;
  314. }
  315. .search-bar {
  316. background-color: #ffffff;
  317. border-radius: 10rpx;
  318. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  319. }
  320. /* 搜索输入框:占满容器剩余空间,放在按钮左侧 */
  321. .search-input {
  322. /* 清除默认输入框样式 */
  323. border: none;
  324. background: transparent;
  325. width: 70%;
  326. margin-left: 10rpx;
  327. }
  328. /* 扫描按钮:放在输入框右侧,距离最右10rpx */
  329. .scan-btn {
  330. justify-content: center;
  331. align-items: center; /* 新增:按钮内部图标垂直居中 */
  332. /* 关键:右侧10rpx边距,实现"距离最右10rpx" */
  333. margin-left: auto; /* 自动推到flex容器最右侧 */
  334. margin-right: 10rpx; /* 与容器右边缘保持10rpx间距 */
  335. }
  336. .download-card {
  337. background: #ffffff;
  338. border-radius: 20rpx;
  339. padding: 24rpx 32rpx;
  340. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  341. display: flex;
  342. flex-direction: column;
  343. margin-bottom: 20rpx;
  344. margin-top: 40rpx;
  345. margin-left: 20rpx;
  346. margin-right: 20rpx;
  347. }
  348. .download-card .view {
  349. margin-bottom: 16rpx;
  350. }
  351. /* 信息行 */
  352. .info-row {
  353. display: flex;
  354. flex-direction: row;
  355. font-size: 28rpx;
  356. color: #33475b;
  357. align-items: center;
  358. }
  359. .info-row>.label {
  360. margin-left: 10rpx;
  361. }
  362. .info-row>.value {
  363. margin-left: 10rpx;
  364. }
  365. .btn-panel {
  366. display: flex;
  367. justify-content: space-between;
  368. align-items: center;
  369. margin-left: 5rpx;
  370. margin-right: 5rpx;
  371. }
  372. .label {
  373. font-weight: bold;
  374. color: #102a43;
  375. min-width: 100rpx;
  376. }
  377. .value {
  378. flex: 1;
  379. white-space: nowrap;
  380. overflow: hidden;
  381. text-overflow: ellipsis;
  382. }
  383. .btn {
  384. align-self: flex-end;
  385. background-color: #00aaff;
  386. color: #fff;
  387. border: none;
  388. border-radius: 32rpx;
  389. padding: 2rpx 30rpx;
  390. font-size: 24rpx;
  391. font-weight: bold;
  392. /* #ifndef APP-ANDROID */
  393. transition: background-color 0.3s ease;
  394. /* #endif */
  395. margin-top: 30rpx;
  396. }
  397. .process-value {
  398. width: 120rpx;
  399. min-width: 100rpx;
  400. text-align: center;
  401. border-radius: 10rpx;
  402. }
  403. .bg-green {
  404. background-color: seagreen;
  405. }
  406. .bg-yellow {
  407. background-color: yellow;
  408. }
  409. .bg-black {
  410. background-color: #102a43;
  411. }
  412. .btn-first {
  413. margin-left: 5rpx;
  414. }
  415. .btn-second {
  416. margin-right: 5rpx;
  417. margin-left: auto;
  418. }
  419. </style>