From d68c5a3ef7025d67a2d92ea3aa84f73ec77ddd5f Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 03 三月 2025 16:36:50 +0800
Subject: [PATCH] 文件下载失败统一拦截
---
src/views/CNAS/resourceDemand/device/component/state.vue | 103 +++++++++++++++------------------------------------
1 files changed, 30 insertions(+), 73 deletions(-)
diff --git a/src/views/CNAS/resourceDemand/device/component/state.vue b/src/views/CNAS/resourceDemand/device/component/state.vue
index 9994f65..b009a65 100644
--- a/src/views/CNAS/resourceDemand/device/component/state.vue
+++ b/src/views/CNAS/resourceDemand/device/component/state.vue
@@ -237,7 +237,17 @@
</div>
</template>
<script>
+import {
+ saveDeviceState,
+ selectDeviceByCode,
+ exportDeviceStatus,
+ deleteDeviceState,
+ deviceStateExport,
+ getDeviceStatePage,
+} from '@/api/cnas/resourceDemand/device.js'
+import { selectUserCondition } from "@/api/business/inspectionTask";
import { dateFormat } from '@/utils/date'
+import { mapGetters } from "vuex";
export default {
props: {
clickNodeVal: {
@@ -246,6 +256,9 @@
return {};
}
}
+ },
+ computed: {
+ ...mapGetters(["nickName"]),
},
data() {
return {
@@ -311,25 +324,24 @@
this.$refs.form.validate((valid) => {
if (valid === true || saveState !== '1submit') {
// 缁欏綋鍓嶇幆鑺傝缃垱寤轰汉涓庢椂闂�
- let user = JSON.parse(localStorage.getItem('user'))
const dateTime = dateFormat(new Date())
// 鑾峰彇褰撳墠鐜妭鎿嶄綔浜轰笌鏃ユ湡
switch (this.currentStep) {
case 0:
- this.form.createUser = user.name
- this.form.submitOperatingPersonnel = user.name
+ this.form.createUser = this.nickName
+ this.form.submitOperatingPersonnel = this.nickName
this.form.submitDate = dateTime
break
case 1:
- this.form.departmentOperatingPersonnel = user.name
+ this.form.departmentOperatingPersonnel = this.nickName
this.form.departmentDate = dateTime
break
case 2:
- this.form.measuringRoomOperatingPersonnel = user.name
+ this.form.measuringRoomOperatingPersonnel = this.nickName
this.form.measuringRoomDate = dateTime
break
case 3:
- this.form.approvalOperatingPersonnel = user.name
+ this.form.approvalOperatingPersonnel = this.nickName
this.form.approvalDate = dateTime
break
default:
@@ -355,11 +367,7 @@
// 鑾峰彇褰撳墠鐘舵��
this.form.currentState = currentStepAction === 4 ? '鍏抽棴' : this.steps[currentStepAction]
this.form.deviceId = this.clickNodeVal.value
- this.$axios.post(this.$api.deviceCheck.saveDeviceState, this.form, {
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(res => {
+ saveDeviceState(this.form).then(res => {
if (res.code == 200) {
this.$message.success('鎻愪氦鎴愬姛')
this.getDeviceStatePage(this.clickNodeVal.value)
@@ -385,7 +393,7 @@
},
openRecordAcceptance() {
// 鑾峰彇璁惧鍩虹淇℃伅
- this.$axios.get(this.$api.deviceScope.selectDeviceByCode + '?id=' + this.clickNodeVal.value).then(res => {
+ selectDeviceByCode({ id: this.clickNodeVal.value }).then(res => {
this.form.deviceName = res.data.deviceName
this.form.specificationModel = res.data.specificationModel
this.form.managementNumber = res.data.managementNumber
@@ -398,7 +406,7 @@
},
// 鑾峰彇璐熻矗浜轰俊鎭帴鍙�
getUserList() {
- this.$axios.get(this.$api.deviceScope.selectUserList).then(res => {
+ selectUserCondition().then(res => {
if (res.code == 200) {
this.responsibleOptions = res.data
}
@@ -418,37 +426,11 @@
// 瀵煎嚭
handleDownOne(row) {
this.outLoading = true
- this.$axios.get(this.$api.deviceCheck.exportDeviceStatus + '?deviceId=' + row.deviceId + '&processNumber=' + row.processNumber, {
- responseType: "blob"
- }).then(res => {
+ exportDeviceStatus({ deviceId: row.deviceId, processNumber: row.processNumber }).then(res => {
this.outLoading = false
const blob = new Blob([res], { type: 'application/octet-stream' });
- //灏咮lob 瀵硅薄杞崲鎴愬瓧绗︿覆
- let reader = new FileReader();
- reader.readAsText(blob, 'utf-8');
- reader.onload = () => {
- try {
- let result = JSON.parse(reader.result);
- if (result.message) {
- this.$message.error(result.message);
- } else {
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '璁惧鍋�/鍚敤.doc';
- link.click();
- this.$message.success('瀵煎嚭鎴愬姛')
- }
- } catch (err) {
- console.log(err);
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '璁惧鍋�/鍚敤.doc';
- link.click();
- this.$message.success('瀵煎嚭鎴愬姛')
- }
- }
+ this.$download.saveAs(blob, '璁惧鍋�/鍚敤.doc')
+ this.$message.success('瀵煎嚭鎴愬姛')
})
},
// 鍒犻櫎
@@ -458,7 +440,7 @@
cancelButtonText: '鍙栨秷',
type: 'warning'
}).then(() => {
- this.$axios.delete(this.$api.deviceCheck.deleteDeviceState + '?stateId=' + row.stateId).then(res => {
+ deleteDeviceState({ stateId: row.stateId }).then(res => {
if (res.code == 200) {
this.$message.success('鍒犻櫎鎴愬姛')
this.getDeviceStatePage(this.clickNodeVal.value)
@@ -470,43 +452,18 @@
message: '宸插彇娑堝垹闄�'
});
});
-
},
//瀵煎嚭
handleDown() {
this.outLoading = true
- this.$axios.post(this.$api.deviceCheck.deviceStateExport, {
+ deviceStateExport({
deviceId: this.clickNodeVal.value,
processNumber: this.search.processNumber
- }, { responseType: "blob" }).then(res => {
+ }).then(res => {
this.outLoading = false
const blob = new Blob([res], { type: 'application/octet-stream' });
- //灏咮lob 瀵硅薄杞崲鎴愬瓧绗︿覆
- let reader = new FileReader();
- reader.readAsText(blob, 'utf-8');
- reader.onload = () => {
- try {
- let result = JSON.parse(reader.result);
- if (result.message) {
- this.$message.error(result.message);
- } else {
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '璁惧鍋滅敤/鍚敤.xlsx';
- link.click();
- this.$message.success('瀵煎嚭鎴愬姛')
- }
- } catch (err) {
- console.log(err);
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '璁惧鍋滅敤/鍚敤.xlsx';
- link.click();
- this.$message.success('瀵煎嚭鎴愬姛')
- }
- }
+ this.$download.saveAs(blob, '璁惧鍋滅敤/鍚敤.xlsx')
+ this.$message.success('瀵煎嚭鎴愬姛')
}).finally(() => {
this.outLoading = false
})
@@ -521,7 +478,7 @@
this.getDeviceStatePage(this.clickNodeVal.value);
},
getDeviceStatePage(deviceId) {
- this.$axios.get(this.$api.deviceCheck.getDeviceStatePage + '?deviceId=' + deviceId + "&size=" + this.search.size + "¤t=" + this.search.current + "&processNumber=" + this.search.processNumber).then(res => {
+ getDeviceStatePage({ deviceId, ...this.search }).then(res => {
if (res.code == 200) {
this.tableDatalist = res.data.records
this.search.total = res.data.total
--
Gitblit v1.9.3