DownloadList.uvue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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('');
  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.photoStatus + e.keyStatus + e.recordStatus ) != 3) {
  199. uni.showToast({
  200. title: '当前任务还未完成!',
  201. icon: 'error'
  202. });
  203. return
  204. }
  205. console.log("开始上传...")
  206. uploadDataToAPI(e.gxpk, () => {
  207. // 回调函数中执行刷新,确保数据都保存好,进度条跑完
  208. uni.reLaunch({ url: '/pages/work/download/DownloadList' })
  209. }).then((res) => {
  210. // 移除这里的刷新逻辑,避免过早刷新
  211. // 处理断点续传
  212. })
  213. }
  214. const enterItem = (id : number) => {
  215. uni.navigateTo({
  216. url: `/pages/work/download/DownloadDetail?id=${id}`
  217. });
  218. }
  219. // 扫描二维码功能
  220. const scanQRCode = () => {
  221. uni.scanCode({
  222. success: (res) => {
  223. // 扫描成功,将结果填充到输入框
  224. productNo.value = res.result;
  225. console.log('扫描结果:', res.result);
  226. },
  227. fail: (err) => {
  228. console.error('扫描失败:', err);
  229. uni.showToast({
  230. title: '扫描失败,请重试',
  231. icon: 'error'
  232. });
  233. }
  234. });
  235. }
  236. defineExpose({
  237. backPressOptions
  238. })
  239. </script>
  240. <style scope>
  241. .container {
  242. padding: 24rpx;
  243. background-color: #f0f4f8;
  244. flex: 1;
  245. display: flex;
  246. flex-direction: column;
  247. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  248. /* #ifndef APP-ANDROID */
  249. min-height: 100vh;
  250. /* #endif */
  251. height: 120rpx;
  252. }
  253. .search-bar {
  254. background-color: #ffffff;
  255. border-radius: 10rpx;
  256. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  257. }
  258. /* 搜索输入框:占满容器剩余空间,放在按钮左侧 */
  259. .search-input {
  260. /* 清除默认输入框样式 */
  261. border: none;
  262. background: transparent;
  263. width: 70%;
  264. margin-left: 10rpx;
  265. }
  266. /* 扫描按钮:放在输入框右侧,距离最右10rpx */
  267. .scan-btn {
  268. justify-content: center;
  269. align-items: center; /* 新增:按钮内部图标垂直居中 */
  270. /* 关键:右侧10rpx边距,实现"距离最右10rpx" */
  271. margin-left: auto; /* 自动推到flex容器最右侧 */
  272. margin-right: 10rpx; /* 与容器右边缘保持10rpx间距 */
  273. }
  274. .download-card {
  275. background: #ffffff;
  276. border-radius: 20rpx;
  277. padding: 24rpx 32rpx;
  278. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  279. display: flex;
  280. flex-direction: column;
  281. margin-bottom: 20rpx;
  282. margin-top: 40rpx;
  283. margin-left: 20rpx;
  284. margin-right: 20rpx;
  285. }
  286. .download-card .view {
  287. margin-bottom: 16rpx;
  288. }
  289. /* 信息行 */
  290. .info-row {
  291. display: flex;
  292. flex-direction: row;
  293. font-size: 28rpx;
  294. color: #33475b;
  295. align-items: center;
  296. }
  297. .info-row>.label {
  298. margin-left: 10rpx;
  299. }
  300. .info-row>.value {
  301. margin-left: 10rpx;
  302. }
  303. .btn-panel {
  304. display: flex;
  305. justify-content: space-between;
  306. align-items: center;
  307. margin-left: 5rpx;
  308. margin-right: 5rpx;
  309. }
  310. .label {
  311. font-weight: bold;
  312. color: #102a43;
  313. min-width: 100rpx;
  314. }
  315. .value {
  316. flex: 1;
  317. white-space: nowrap;
  318. overflow: hidden;
  319. text-overflow: ellipsis;
  320. }
  321. .btn {
  322. align-self: flex-end;
  323. background-color: #00aaff;
  324. color: #fff;
  325. border: none;
  326. border-radius: 32rpx;
  327. padding: 2rpx 30rpx;
  328. font-size: 24rpx;
  329. font-weight: bold;
  330. /* #ifndef APP-ANDROID */
  331. transition: background-color 0.3s ease;
  332. /* #endif */
  333. margin-top: 30rpx;
  334. }
  335. .process-value {
  336. width: 120rpx;
  337. min-width: 100rpx;
  338. text-align: center;
  339. border-radius: 10rpx;
  340. }
  341. .bg-green {
  342. background-color: seagreen;
  343. }
  344. .bg-yellow {
  345. background-color: yellow;
  346. }
  347. .bg-black {
  348. background-color: #102a43;
  349. }
  350. .btn-first {
  351. margin-left: 5rpx;
  352. }
  353. .btn-second {
  354. margin-right: 5rpx;
  355. margin-left: auto;
  356. }
  357. </style>