diff --git a/fuintAdmin/src/main.js b/fuintAdmin/src/main.js index 43b4aa1..828b5b9 100644 --- a/fuintAdmin/src/main.js +++ b/fuintAdmin/src/main.js @@ -12,7 +12,7 @@ import store from './store' import router from './router' import directive from './directive' // directive import plugins from './plugins' // plugins -import { download } from '@/utils/request' +import { download,download1,download2 } from '@/utils/request' import './assets/icons' // icon import './permission' // permission control @@ -42,14 +42,19 @@ import Print from 'vue-print-nb' import TreeSelect from '@/components/TreeSelect' // 会员选择组件 import UserSelect from '@/components/UserSelect' +import { selectDictLabel, selectDictLabels} from "@/utils/ruoyi"; // 全局方法挂载 Vue.prototype.getConfigKey = getConfigKey +Vue.prototype.selectDictLabel = selectDictLabel +Vue.prototype.selectDictLabels = selectDictLabels Vue.prototype.parseTime = parseTime Vue.prototype.resetForm = resetForm Vue.prototype.addDateRange = addDateRange Vue.prototype.getName = getName Vue.prototype.download = download +Vue.prototype.download1 = download1 +Vue.prototype.download2 = download2 Vue.prototype.handleTree = handleTree // 全局组件挂载 diff --git a/fuintAdmin/src/utils/request.js b/fuintAdmin/src/utils/request.js index 178388b..8836f6a 100644 --- a/fuintAdmin/src/utils/request.js +++ b/fuintAdmin/src/utils/request.js @@ -1,14 +1,15 @@ import axios from 'axios' -import { Notification, MessageBox, Message } from 'element-ui' +import { Notification, MessageBox, Message, Loading } from 'element-ui' import store from '@/store' import { getToken } from '@/utils/auth' import errorCode from '@/utils/errorCode' import { tansParams } from "@/utils/fuint"; import cache from '@/plugins/cache' - +import request from '@/utils/request' +import { blobValidate } from "@/utils/ruoyi"; // 是否显示重新登录 export let isRelogin = { show: false }; - +let downloadLoadingInstance; axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' // 创建axios实例 const service = axios.create({ @@ -135,6 +136,42 @@ export function download(url, params) { window.open(url, '_blank') } +// 通用下载方法 +export function download1(url, params) { + return request({ + url: url + '?token='+ getToken() + '&'+ param(params), + method: 'get' + }) + // url = process.env.VUE_APP_BASE_API + url + '?token='+ getToken() + '&'+ param(params) + // window.open(url, '_blank') +} +// 通用下载方法 +export function download2(url, params, filename, config) { + downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", }) + return service.post(url, params, { + transformRequest: [(params) => { return tansParams(params) }], + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + responseType: 'blob', + ...config + }).then(async (data) => { + const isBlob = blobValidate(data); + if (isBlob) { + const blob = new Blob([data]) + saveAs(blob, filename) + } else { + const resText = await data.text(); + const rspObj = JSON.parse(resText); + const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'] + Message.error(errMsg); + } + downloadLoadingInstance.close(); + }).catch((r) => { + console.error(r) + Message.error('下载文件出现错误,请联系管理员!') + downloadLoadingInstance.close(); + }) +} + // 组织参数 export function param(data) { let url = '' diff --git a/fuintAdmin/src/views/order/index.vue b/fuintAdmin/src/views/order/index.vue index aa1a7a5..d10a9bc 100644 --- a/fuintAdmin/src/views/order/index.vue +++ b/fuintAdmin/src/views/order/index.vue @@ -91,6 +91,13 @@ 查询 重置 + 导入 @@ -387,6 +394,32 @@ + + + + +
将文件拖到此处,或点击上传
+
+ 仅允许导入xls、xlsx格式文件。 + 下载模板 +
+
+ +
@@ -395,6 +428,7 @@ import { getName } from "@/utils/fuint"; import { getOrderList, updateOrderStatus, getOrderInfo, saveOrder, deleteOrder, verifyOrder, delivered } from "@/api/order"; import { doRefund } from "@/api/refund"; import orderPrintDialog from '../cashier/components/orderPrintDialog' +import { getToken } from "@/utils/auth"; export default { name: "OrderIndex", components: { @@ -486,7 +520,22 @@ export default { { required: true, message: "退款金额不能为空", trigger: "blur" }, { pattern: /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/, message: `请输入正确的退款金额`, trigger: 'blur' } ] - } + }, + // 用户导入参数 + upload: { + // 是否显示弹出层(用户导入) + open: false, + // 弹出层标题(用户导入) + title: "", + // 是否禁用上传 + isUploading: false, + // 是否更新已经存在的用户数据 + updateSupport: 0, + // 设置上传的请求头部 + headers: { 'Access-Token': getToken() }, + // 上传的地址 + url: process.env.VUE_APP_BASE_API + "/backendApi/order/importData" + }, }; }, created() { @@ -768,6 +817,32 @@ export default { break; } }, + /** 导入按钮操作 */ + handleImport() { + this.upload.title = "用户导入"; + this.upload.open = true; + }, + /** 下载模板操作 */ + importTemplate() { + this.download2('/backendApi/order/exportTemplate', { + }, `订单模板${new Date().getTime()}.xlsx`) + }, + // 文件上传中处理 + handleFileUploadProgress(event, file, fileList) { + this.upload.isUploading = true; + }, + // 文件上传成功处理 + handleFileSuccess(response, file, fileList) { + this.upload.open = false; + this.upload.isUploading = false; + this.$refs.upload.clearFiles(); + this.$alert("
" + response.msg + "
", "导入结果", { dangerouslyUseHTMLString: true }); + this.getList(); + }, + // 提交上传文件 + submitFileForm() { + this.$refs.upload.submit(); + } } }; diff --git a/fuintAdmin/src/views/store/list.vue b/fuintAdmin/src/views/store/list.vue index c52615e..a01c4c2 100644 --- a/fuintAdmin/src/views/store/list.vue +++ b/fuintAdmin/src/views/store/list.vue @@ -329,6 +329,13 @@ +