DownloadList.uvue 9.8 KB

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