DownloadList.uvue 9.8 KB

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