DownloadList.uvue 9.1 KB

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