DownloadList.uvue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. // 回调函数中执行刷新,确保数据都保存好,进度条跑完
  218. uni.reLaunch({ url: '/pages/work/download/DownloadList' })
  219. }).then((res) => {
  220. // 移除这里的刷新逻辑,避免过早刷新
  221. // 处理断点续传
  222. })
  223. }
  224. const enterItem = (id : number) => {
  225. uni.navigateTo({
  226. url: `/pages/work/download/DownloadDetail?id=${id}`
  227. });
  228. }
  229. // 扫描二维码功能
  230. const scanQRCode = () => {
  231. uni.scanCode({
  232. success: (res) => {
  233. // 扫描成功,将结果填充到输入框
  234. productNo.value = res.result;
  235. console.log('扫描结果:', res.result);
  236. },
  237. fail: (err) => {
  238. console.error('扫描失败:', err);
  239. uni.showToast({
  240. title: '扫描失败,请重试',
  241. icon: 'error'
  242. });
  243. }
  244. });
  245. }
  246. const search = async () => {
  247. // 检查productNo是否为空
  248. if (productNo.value == null || productNo.value.trim() == '') {
  249. uni.showToast({
  250. title: '请输入产品号',
  251. icon: 'error'
  252. });
  253. return;
  254. }
  255. // 显示加载提示
  256. uni.showLoading({
  257. title: '搜索中...'
  258. });
  259. try {
  260. // 使用getRecordInfoList函数并传入productNo.value作为第一个参数
  261. let query = `m.gxpk like '%${productNo.value}%'`
  262. const res = await getTaskInfoList(query, null);
  263. console.log('搜索结果:', res);
  264. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
  265. let searchResults = [] as Task[];
  266. if (dataList != null && dataList.length > 0) {
  267. dataList.forEach(item => {
  268. if (item != null) {
  269. try {
  270. let download = JSON.parse<Task>(item.toJSONString());
  271. if (download != null) {
  272. searchResults.push(download);
  273. }
  274. } catch (e) {
  275. console.error('解析数据失败:', e);
  276. }
  277. }
  278. });
  279. }
  280. // 更新downloads数组,显示搜索结果
  281. downloads.value = searchResults;
  282. // 如果没有搜索到结果,显示提示
  283. if (searchResults.length === 0) {
  284. uni.showToast({
  285. title: '未找到相关数据',
  286. icon: 'none'
  287. });
  288. }
  289. } catch (error) {
  290. console.error('搜索失败:', error);
  291. uni.showToast({
  292. title: '搜索失败,请重试',
  293. icon: 'error'
  294. });
  295. } finally {
  296. // 隐藏加载提示
  297. uni.hideLoading();
  298. }
  299. }
  300. defineExpose({
  301. backPressOptions
  302. })
  303. </script>
  304. <style scope>
  305. .container {
  306. padding: 24rpx;
  307. background-color: #f0f4f8;
  308. flex: 1;
  309. display: flex;
  310. flex-direction: column;
  311. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  312. /* #ifndef APP-ANDROID */
  313. min-height: 100vh;
  314. /* #endif */
  315. height: 120rpx;
  316. }
  317. .search-bar {
  318. background-color: #ffffff;
  319. border-radius: 10rpx;
  320. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  321. }
  322. /* 搜索输入框:占满容器剩余空间,放在按钮左侧 */
  323. .search-input {
  324. /* 清除默认输入框样式 */
  325. border: none;
  326. background: transparent;
  327. width: 70%;
  328. margin-left: 10rpx;
  329. }
  330. /* 扫描按钮:放在输入框右侧,距离最右10rpx */
  331. .scan-btn {
  332. justify-content: center;
  333. align-items: center; /* 新增:按钮内部图标垂直居中 */
  334. /* 关键:右侧10rpx边距,实现"距离最右10rpx" */
  335. margin-left: auto; /* 自动推到flex容器最右侧 */
  336. margin-right: 10rpx; /* 与容器右边缘保持10rpx间距 */
  337. }
  338. .download-card {
  339. background: #ffffff;
  340. border-radius: 20rpx;
  341. padding: 24rpx 32rpx;
  342. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  343. display: flex;
  344. flex-direction: column;
  345. margin-bottom: 20rpx;
  346. margin-top: 40rpx;
  347. margin-left: 20rpx;
  348. margin-right: 20rpx;
  349. }
  350. .download-card .view {
  351. margin-bottom: 16rpx;
  352. }
  353. /* 信息行 */
  354. .info-row {
  355. display: flex;
  356. flex-direction: row;
  357. font-size: 28rpx;
  358. color: #33475b;
  359. align-items: center;
  360. }
  361. .info-row>.label {
  362. margin-left: 10rpx;
  363. }
  364. .info-row>.value {
  365. margin-left: 10rpx;
  366. }
  367. .btn-panel {
  368. display: flex;
  369. justify-content: space-between;
  370. align-items: center;
  371. margin-left: 5rpx;
  372. margin-right: 5rpx;
  373. }
  374. .label {
  375. font-weight: bold;
  376. color: #102a43;
  377. min-width: 100rpx;
  378. }
  379. .value {
  380. flex: 1;
  381. white-space: nowrap;
  382. overflow: hidden;
  383. text-overflow: ellipsis;
  384. }
  385. .btn {
  386. align-self: flex-end;
  387. background-color: #00aaff;
  388. color: #fff;
  389. border: none;
  390. border-radius: 32rpx;
  391. padding: 2rpx 30rpx;
  392. font-size: 24rpx;
  393. font-weight: bold;
  394. /* #ifndef APP-ANDROID */
  395. transition: background-color 0.3s ease;
  396. /* #endif */
  397. margin-top: 30rpx;
  398. }
  399. .process-value {
  400. width: 120rpx;
  401. min-width: 100rpx;
  402. text-align: center;
  403. border-radius: 10rpx;
  404. }
  405. .bg-green {
  406. background-color: seagreen;
  407. }
  408. .bg-yellow {
  409. background-color: yellow;
  410. }
  411. .bg-black {
  412. background-color: #102a43;
  413. }
  414. .btn-first {
  415. margin-left: 5rpx;
  416. }
  417. .btn-second {
  418. margin-right: 5rpx;
  419. margin-left: auto;
  420. }
  421. </style>