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