Преглед изворни кода

用户企业编辑和订单导出修改

“陈博论” пре 7 месеци
родитељ
комит
c6ccd9d684

+ 11 - 5
web/src/api/backend/order/order.ts

@@ -2,9 +2,15 @@ import createAxios from '/@/utils/axios'
 
 // 列表
 export function handlexport(data: anyObj) {
-    return createAxios({
-        url: '/admin/order.Order/export',
-        method: 'get',
-        params: data,
-    })
+    return createAxios(
+        {
+            url: '/admin/order.Order/export',
+            method: 'get',
+            params: data,
+            responseType: 'blob'
+        },
+        {
+            reductDataFormat: false
+        },
+    )
 }

+ 84 - 0
web/src/utils/downloadCallback.ts

@@ -0,0 +1,84 @@
+type NavigatorWithSaveBlob = Navigator & {
+	msSaveBlob?: (blob: Blob, defaultName?: string) => boolean;
+};
+
+function saveBlobForLegacyBrowser(blob: Blob, fileName: string) {
+	const nav = navigator as NavigatorWithSaveBlob;
+	if (typeof nav.msSaveBlob === "function") {
+		nav.msSaveBlob(blob, fileName);
+	}
+}
+
+export function downloadCallback(res: { data: any; }, fileName: string) {
+	const content = res.data;
+	const blob = new Blob([content]);
+	if ("download" in document.createElement("a")) {
+		// 非IE下载
+		const elink = document.createElement("a");
+		elink.download = fileName;
+		elink.style.display = "none";
+		elink.href = URL.createObjectURL(blob);
+		document.body.appendChild(elink);
+		elink.click();
+		URL.revokeObjectURL(elink.href); // 释放URL 对象
+		document.body.removeChild(elink);
+	} else {
+		// IE10+下载
+		saveBlobForLegacyBrowser(blob, fileName);
+	}
+}
+
+export function downloadCallback2(res: { data: any; }, fileName: string) {
+	const content = res.data;
+	let blob: Blob;
+
+	if (content instanceof Blob) {
+		blob = content;
+	} else if (fileName.toLowerCase().endsWith(".csv")) {
+		let csvContent: string;
+
+		if (typeof content === "string") {
+			csvContent = content;
+		} else if (content instanceof ArrayBuffer) {
+			csvContent = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8").decode(content) : String(content);
+		} else if (ArrayBuffer.isView(content)) {
+			const view = content as ArrayBufferView;
+			csvContent = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8").decode(view) : String(content);
+		} else {
+			csvContent = String(content);
+		}
+
+		blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
+	} else if (fileName.toLowerCase().endsWith(".zip")) {
+		const zipParts: BlobPart[] = [];
+
+		if (content instanceof ArrayBuffer || ArrayBuffer.isView(content)) {
+			zipParts.push(content);
+		} else if (typeof content === "string") {
+			if (typeof TextEncoder !== "undefined") {
+				zipParts.push(new TextEncoder().encode(content));
+			} else {
+				zipParts.push(content);
+			}
+		} else {
+			zipParts.push(content as BlobPart);
+		}
+
+		blob = new Blob(zipParts, { type: "application/zip" });
+	} else {
+		blob = new Blob([content]);
+	}
+
+	if ("download" in document.createElement("a")) {
+		const elink = document.createElement("a");
+		elink.download = fileName;
+		elink.style.display = "none";
+		elink.href = URL.createObjectURL(blob);
+		document.body.appendChild(elink);
+		elink.click();
+		URL.revokeObjectURL(elink.href);
+		document.body.removeChild(elink);
+	} else {
+		saveBlobForLegacyBrowser(blob, fileName);
+	}
+}

+ 73 - 58
web/src/views/backend/order/order/index.vue

@@ -12,17 +12,20 @@
 </template>
 
 <script setup lang="ts">
-import {  provide, } from 'vue'
+import { provide, } from 'vue'
 import baTableClass from '/@/utils/baTable'
 import Table from '/@/components/table/index.vue'
 import TableHeader from '/@/components/table/header/index.vue'
 import { baTableApi } from '/@/api/common'
 import { useI18n } from 'vue-i18n'
 import { handlexport } from '/@/api/backend/order/order'
+import { downloadCallback } from '/@/utils/downloadCallback'
+import dayjs from 'dayjs'
+import { ElMessage, } from 'element-plus'
 import { Download } from '@element-plus/icons-vue'
 
 defineOptions({
-    name: 'order/order',
+	name: 'order/order',
 })
 
 
@@ -32,61 +35,61 @@ const baTable = new baTableClass(
 	new baTableApi('/admin/order.Order/'),
 	{
 		column: [
-			{ 
-				label: '编号', 
-				prop: 'id', 
-				align: 'center', 
+			{
+				label: '编号',
+				prop: 'id',
+				align: 'center',
 				width: 70,
 			},
-			{ 
-				label: '订单编号', 
-				prop: 'order_no', 
-				align: 'center', 
+			{
+				label: '订单编号',
+				prop: 'order_no',
+				align: 'center',
 				minWidth: 180,
 			},
-			{ 
-				label: '商品名称', 
-				prop: 'item_name', 
-				align: 'center', 
+			{
+				label: '商品名称',
+				prop: 'item_name',
+				align: 'center',
 				minWidth: 140,
 			},
-			{ 
-				label: '购买数量', 
-				prop: 'quantity', 
-				align: 'center', 
+			{
+				label: '购买数量',
+				prop: 'quantity',
+				align: 'center',
 				minWidth: 100,
 			},
-			{ 
-				label: '商品单价', 
-				prop: 'unit_price', 
-				align: 'center', 
+			{
+				label: '商品单价',
+				prop: 'unit_price',
+				align: 'center',
 				minWidth: 110,
 			},
-			{ 
-				label: '会员名称', 
-				prop: 'name', 
-				align: 'center', 
+			{
+				label: '会员名称',
+				prop: 'name',
+				align: 'center',
 				minWidth: 100,
 			},
-			{ 
-				label: '支付金额', 
-				prop: 'pay_amount', 
-				align: 'center', 
+			{
+				label: '支付金额',
+				prop: 'pay_amount',
+				align: 'center',
 				minWidth: 110,
 			},
-			{ 
-				label: '最后佣金', 
-				prop: 'commission_amount', 
-				align: 'center', 
+			{
+				label: '最后佣金',
+				prop: 'commission_amount',
+				align: 'center',
 				minWidth: 110,
 			},
-			{ 
-				label: '支付方式', 
-				prop: 'pay_method', 
-				align: 'center', 
+			{
+				label: '支付方式',
+				prop: 'pay_method',
+				align: 'center',
 				minWidth: 100,
 				render: 'tag',
-				effect:'dark',
+				effect: 'dark',
 				custom: {
 					'银行卡': 'warning',
 					'支付宝': '',
@@ -98,10 +101,10 @@ const baTable = new baTableClass(
 					'微信': '微信',
 				},
 			},
-			{ 
-				label: '订单状态', 
-				prop: 'pay_status', 
-				align: 'center', 
+			{
+				label: '订单状态',
+				prop: 'pay_status',
+				align: 'center',
 				render: 'tag',
 				custom: {
 					'0': 'warning',
@@ -115,16 +118,16 @@ const baTable = new baTableClass(
 				},
 				minWidth: 100,
 			},
-			
-			{ 
-				label: '支付时间', 
-				prop: 'pay_time', 
+
+			{
+				label: '支付时间',
+				prop: 'pay_time',
 				align: 'center',
 				minWidth: 170,
 			},
-			{ 
-				label: '订单日期', 
-				prop: 'order_time', 
+			{
+				label: '订单日期',
+				prop: 'order_time',
 				align: 'center',
 				minWidth: 120,
 			},
@@ -144,7 +147,7 @@ const baTable = new baTableClass(
 	},
 	{
 		defaultItems: {
-		
+
 		},
 	},
 )
@@ -160,14 +163,26 @@ const seachList = () => {
 }
 
 // 导出
-const onExport = ()=>{
-	handlexport({}).then((res)=>{
-		console.log(res,'ddddd');
-		
+const onExport = () => {
+	baTable.table.loading = true
+	handlexport({}).then((res) => {
+		if (res.data) {
+			downloadCallback(res, `订单数据--${dayjs().format('YYYYMMDDHHmmss')}.xlsx`);
+		} else {
+			ElMessage({
+				type: 'error',
+				message: '下载失败,请重试'
+			})
+		}
+	}).catch(() => {
+		ElMessage({
+			type: 'error',
+			message: '下载失败,请重试'
+		})
+	}).finally(() => {
+		baTable.table.loading = false
 	})
 }
 
 </script>
-<style scoped lang="scss">
-
-</style>
+<style scoped lang="scss"></style>

+ 3 - 3
web/src/views/backend/userCenter/user/popupForm.vue

@@ -50,9 +50,9 @@
                             show-password
                         />
                     </el-form-item>
-                    <el-form-item label="企业" prop="company">
+                    <el-form-item label="企业" prop="company_id">
                         <el-select
-                            v-model="baTable.form.items!.company"
+                            v-model="baTable.form.items!.company_id"
                             placeholder="请选择企业"
                             style="width: 100%"
                             clearable
@@ -158,7 +158,7 @@ const btnSubmit = () => {
                 id: baTable.form.items!.id,
                 name: baTable.form.items!.username,
                 email:baTable.form.items!.email,
-                company_id:baTable.form.items!.company,
+                company_id:baTable.form.items!.company_id,
                 password:baTable.form.items!.password,
                 status: baTable.form.items!.status,
             }