DownloadList.uvue 9.3 KB

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