DownloadList.uvue 9.5 KB

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