mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2024-11-01 14:10:27 +08:00
添加导入导出组件
This commit is contained in:
parent
6dde8feb32
commit
bbd057dbf0
132
build/cool/temp/eps.d.ts
vendored
132
build/cool/temp/eps.d.ts
vendored
@ -69,13 +69,6 @@ declare namespace Eps {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface DemoUserEntity {
|
||||
/**
|
||||
* 任意键值
|
||||
*/
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface DictInfoEntity {
|
||||
/**
|
||||
* 任意键值
|
||||
@ -132,13 +125,6 @@ declare namespace Eps {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface UserAddressEntity {
|
||||
/**
|
||||
* 任意键值
|
||||
*/
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface UserInfoEntity {
|
||||
/**
|
||||
* 任意键值
|
||||
@ -1132,63 +1118,6 @@ declare namespace Eps {
|
||||
request: Service["request"];
|
||||
}
|
||||
|
||||
interface DemoUser {
|
||||
/**
|
||||
* delete
|
||||
*/
|
||||
delete(data?: any): Promise<any>;
|
||||
/**
|
||||
* update
|
||||
*/
|
||||
update(data?: any): Promise<any>;
|
||||
/**
|
||||
* info
|
||||
*/
|
||||
info(data?: any): Promise<DemoUserEntity>;
|
||||
/**
|
||||
* list
|
||||
*/
|
||||
list(data?: any): Promise<DemoUserEntity[]>;
|
||||
/**
|
||||
* page
|
||||
*/
|
||||
page(data?: any): Promise<{
|
||||
pagination: { size: number; page: number; total: number };
|
||||
list: DemoUserEntity[];
|
||||
[key: string]: any;
|
||||
}>;
|
||||
/**
|
||||
* add
|
||||
*/
|
||||
add(data?: any): Promise<any>;
|
||||
/**
|
||||
* 权限标识
|
||||
*/
|
||||
permission: {
|
||||
delete: string;
|
||||
update: string;
|
||||
info: string;
|
||||
list: string;
|
||||
page: string;
|
||||
add: string;
|
||||
};
|
||||
/**
|
||||
* 权限状态
|
||||
*/
|
||||
_permission: {
|
||||
delete: boolean;
|
||||
update: boolean;
|
||||
info: boolean;
|
||||
list: boolean;
|
||||
page: boolean;
|
||||
add: boolean;
|
||||
};
|
||||
/**
|
||||
* 请求
|
||||
*/
|
||||
request: Service["request"];
|
||||
}
|
||||
|
||||
interface DictInfo {
|
||||
/**
|
||||
* delete
|
||||
@ -1756,63 +1685,6 @@ declare namespace Eps {
|
||||
request: Service["request"];
|
||||
}
|
||||
|
||||
interface UserAddress {
|
||||
/**
|
||||
* delete
|
||||
*/
|
||||
delete(data?: any): Promise<any>;
|
||||
/**
|
||||
* update
|
||||
*/
|
||||
update(data?: any): Promise<any>;
|
||||
/**
|
||||
* info
|
||||
*/
|
||||
info(data?: any): Promise<UserAddressEntity>;
|
||||
/**
|
||||
* list
|
||||
*/
|
||||
list(data?: any): Promise<UserAddressEntity[]>;
|
||||
/**
|
||||
* page
|
||||
*/
|
||||
page(data?: any): Promise<{
|
||||
pagination: { size: number; page: number; total: number };
|
||||
list: UserAddressEntity[];
|
||||
[key: string]: any;
|
||||
}>;
|
||||
/**
|
||||
* add
|
||||
*/
|
||||
add(data?: any): Promise<any>;
|
||||
/**
|
||||
* 权限标识
|
||||
*/
|
||||
permission: {
|
||||
delete: string;
|
||||
update: string;
|
||||
info: string;
|
||||
list: string;
|
||||
page: string;
|
||||
add: string;
|
||||
};
|
||||
/**
|
||||
* 权限状态
|
||||
*/
|
||||
_permission: {
|
||||
delete: boolean;
|
||||
update: boolean;
|
||||
info: boolean;
|
||||
list: boolean;
|
||||
page: boolean;
|
||||
add: boolean;
|
||||
};
|
||||
/**
|
||||
* 请求
|
||||
*/
|
||||
request: Service["request"];
|
||||
}
|
||||
|
||||
interface UserInfo {
|
||||
/**
|
||||
* delete
|
||||
@ -1894,12 +1766,12 @@ declare namespace Eps {
|
||||
};
|
||||
};
|
||||
cloud: { db: CloudDb; func: { info: CloudFuncInfo; log: CloudFuncLog } };
|
||||
demo: { goods: DemoGoods; user: DemoUser };
|
||||
demo: { goods: DemoGoods };
|
||||
dict: { info: DictInfo; type: DictType };
|
||||
iot: { device: IotDevice; message: IotMessage; mqtt: IotMqtt };
|
||||
recycle: { data: RecycleData };
|
||||
space: { info: SpaceInfo; type: SpaceType };
|
||||
task: { info: TaskInfo };
|
||||
user: { address: UserAddress; info: UserInfo };
|
||||
user: { info: UserInfo };
|
||||
};
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
[["/admin/base/comm","",[["/personUpdate","post"],["/uploadMode","get"],["/permmenu","get"],["/person","get"],["/upload","post"],["/logout","post"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/open","",[["/refreshToken","get"],["/captcha","get"],["/login","post"],["/html","get"],["/eps","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/department","BaseSysDepartmentEntity",[["/delete","post"],["/update","post"],["/order","post"],["/list","post"],["/add","post"],["/page"],["/info"]]],["/admin/base/sys/log","BaseSysLogEntity",[["/setKeep","post"],["/getKeep","get"],["/clear","post"],["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/menu","BaseSysMenuEntity",[["/create","post"],["/delete","post"],["/update","post"],["/parse","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/param","BaseSysParamEntity",[["/delete","post"],["/update","post"],["/html","get"],["/info","get"],["/page","post"],["/add","post"],["/list"]]],["/admin/base/sys/role","BaseSysRoleEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/user","BaseSysUserEntity",[["/delete","post"],["/update","post"],["/move","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/db","CloudDBEntity",[["/initEntity","post"],["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/info","CloudFuncInfoEntity",[["/invoke","post"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/log","CloudFuncLogEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/demo/goods","DemoGoodsEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/demo/user","DemoUserEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/info","DictInfoEntity",[["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/type","DictTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/device","IotDeviceEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/message","IotMessageEntity",[["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/iot/mqtt","",[["/publish","post"],["/config","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/recycle/data","RecycleDataEntity",[["/restore","post"],["/info","get"],["/page","post"],["/list"],["/update"],["/delete"],["/add"]]],["/admin/space/info","SpaceInfoEntity",[["/getConfig","get"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/space/type","SpaceTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/task/info","TaskInfoEntity",[["/delete","post"],["/update","post"],["/start","post"],["/once","post"],["/stop","post"],["/info","get"],["/page","post"],["/log","get"],["/add","post"],["/list"]]],["/admin/user/address","UserAddressEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/user/info","UserInfoEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/chat/message","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/chat/session","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/test","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]]]
|
||||
[["/admin/base/comm","",[["/personUpdate","post"],["/uploadMode","get"],["/permmenu","get"],["/person","get"],["/upload","post"],["/logout","post"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/open","",[["/refreshToken","get"],["/captcha","get"],["/login","post"],["/html","get"],["/eps","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/department","BaseSysDepartmentEntity",[["/delete","post"],["/update","post"],["/order","post"],["/list","post"],["/add","post"],["/page"],["/info"]]],["/admin/base/sys/log","BaseSysLogEntity",[["/setKeep","post"],["/getKeep","get"],["/clear","post"],["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/menu","BaseSysMenuEntity",[["/create","post"],["/delete","post"],["/update","post"],["/parse","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/param","BaseSysParamEntity",[["/delete","post"],["/update","post"],["/html","get"],["/info","get"],["/page","post"],["/add","post"],["/list"]]],["/admin/base/sys/role","BaseSysRoleEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/user","BaseSysUserEntity",[["/delete","post"],["/update","post"],["/move","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/db","CloudDBEntity",[["/initEntity","post"],["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/info","CloudFuncInfoEntity",[["/invoke","post"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/log","CloudFuncLogEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/demo/goods","DemoGoodsEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/info","DictInfoEntity",[["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/type","DictTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/device","IotDeviceEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/message","IotMessageEntity",[["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/iot/mqtt","",[["/publish","post"],["/config","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/recycle/data","RecycleDataEntity",[["/restore","post"],["/info","get"],["/page","post"],["/list"],["/update"],["/delete"],["/add"]]],["/admin/space/info","SpaceInfoEntity",[["/getConfig","get"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/space/type","SpaceTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/task/info","TaskInfoEntity",[["/delete","post"],["/update","post"],["/start","post"],["/once","post"],["/stop","post"],["/info","get"],["/page","post"],["/log","get"],["/add","post"],["/list"]]],["/admin/user/info","UserInfoEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/chat/message","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/chat/session","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/test","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]]]
|
@ -35,7 +35,7 @@
|
||||
"vue-echarts": "^6.2.3",
|
||||
"vue-router": "^4.1.6",
|
||||
"vuedraggable": "^4.1.0",
|
||||
"xlsx": "^0.18.5"
|
||||
"xlsx": "0.16.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.6",
|
||||
|
BIN
public/用户导入模版.xlsx
Normal file
BIN
public/用户导入模版.xlsx
Normal file
Binary file not shown.
@ -17,43 +17,34 @@
|
||||
<cl-pagination />
|
||||
</cl-row>
|
||||
|
||||
<cl-upsert ref="Upsert">
|
||||
<template #slot-content="{ scope }">
|
||||
<div>
|
||||
<el-radio-group :model-value="tab.value" @change="onTabChange">
|
||||
<el-radio
|
||||
v-for="(item, index) in tab.list"
|
||||
:key="index"
|
||||
:label="item.value"
|
||||
>{{ item.label }}</el-radio
|
||||
>
|
||||
</el-radio-group>
|
||||
|
||||
<cl-editor :name="tab.value" v-model="scope.data" v-if="tab.value" />
|
||||
</div>
|
||||
</template>
|
||||
</cl-upsert>
|
||||
<cl-upsert ref="Upsert" />
|
||||
</cl-crud>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="sys-param" setup>
|
||||
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
|
||||
import { ElMessageBox } from "element-plus";
|
||||
import { Document } from "@element-plus/icons-vue";
|
||||
import { reactive } from "vue";
|
||||
import { useCool } from "/@/cool";
|
||||
|
||||
const { service } = useCool();
|
||||
|
||||
const tab = reactive({
|
||||
value: "",
|
||||
list: [
|
||||
// 选项
|
||||
const options = reactive({
|
||||
dataType: [
|
||||
{
|
||||
label: "代码编辑器",
|
||||
value: "cl-editor-monaco"
|
||||
label: "字符串",
|
||||
value: 0,
|
||||
type: "info"
|
||||
},
|
||||
{
|
||||
label: "富文本编辑器",
|
||||
value: "cl-editor-wang"
|
||||
label: "富文本",
|
||||
value: 1,
|
||||
type: "success"
|
||||
},
|
||||
{
|
||||
label: "文件",
|
||||
value: 2
|
||||
}
|
||||
]
|
||||
});
|
||||
@ -81,10 +72,10 @@ const Table = useTable({
|
||||
minWidth: 150
|
||||
},
|
||||
{
|
||||
label: "数据",
|
||||
prop: "data",
|
||||
label: "数据类型",
|
||||
prop: "dataType",
|
||||
minWidth: 150,
|
||||
showOverflowTooltip: true
|
||||
dict: options.dataType
|
||||
},
|
||||
{
|
||||
label: "备注",
|
||||
@ -94,8 +85,7 @@ const Table = useTable({
|
||||
},
|
||||
{
|
||||
label: "操作",
|
||||
type: "op",
|
||||
buttons: ["edit", "delete"]
|
||||
type: "op"
|
||||
}
|
||||
]
|
||||
});
|
||||
@ -129,10 +119,54 @@ const Upsert = useUpsert({
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: "data",
|
||||
label: "数据",
|
||||
prop: "dataType",
|
||||
label: "类型",
|
||||
value: 0,
|
||||
component: {
|
||||
name: "slot-content"
|
||||
name: "el-radio-group",
|
||||
options: options.dataType
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: "data_0",
|
||||
label: "数据",
|
||||
hidden({ scope }) {
|
||||
return scope.dataType != 0;
|
||||
},
|
||||
component: {
|
||||
name: "el-input",
|
||||
props: {
|
||||
rows: 6,
|
||||
type: "textarea"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: "data_1",
|
||||
label: "数据",
|
||||
hidden({ scope }) {
|
||||
return scope.dataType != 1;
|
||||
},
|
||||
component: {
|
||||
name: "cl-editor",
|
||||
props: {
|
||||
name: "cl-editor-wang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: "data_2",
|
||||
label: "数据",
|
||||
hidden({ scope }) {
|
||||
return scope.dataType != 2;
|
||||
},
|
||||
component: {
|
||||
name: "cl-upload",
|
||||
props: {
|
||||
icon: Document,
|
||||
multiple: true,
|
||||
type: "file"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -150,19 +184,17 @@ const Upsert = useUpsert({
|
||||
],
|
||||
|
||||
onOpened(data) {
|
||||
tab.value = /<*>/g.test(data.data) ? tab.list[1].value : tab.list[0].value;
|
||||
data[`data_${data.dataType}`] = data.data;
|
||||
},
|
||||
|
||||
onSubmit(data, { next }) {
|
||||
next({
|
||||
...data,
|
||||
data: data[`data_${data.dataType}`],
|
||||
data_0: undefined,
|
||||
data_1: undefined,
|
||||
data_2: undefined
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 切换编辑器
|
||||
function onTabChange(name: any) {
|
||||
ElMessageBox.confirm("切换编辑器会清空输入内容,是否继续?", "提示", {
|
||||
type: "warning"
|
||||
})
|
||||
.then(() => {
|
||||
tab.value = name;
|
||||
Upsert.value?.setForm("data", "");
|
||||
})
|
||||
.catch(() => null);
|
||||
}
|
||||
</script>
|
||||
|
@ -20,6 +20,10 @@
|
||||
|
||||
<cl-flex1 />
|
||||
|
||||
<!-- 导入 -->
|
||||
<cl-import-btn template="/用户导入模版.xlsx" />
|
||||
|
||||
<!-- 导出 -->
|
||||
<cl-export-btn :columns="Table?.columns" />
|
||||
|
||||
<!-- 自定义列 -->
|
||||
|
@ -1,7 +0,0 @@
|
||||
import { ModuleConfig } from "/@/cool";
|
||||
|
||||
export default (): ModuleConfig => {
|
||||
return {
|
||||
components: [import("./components/export-btn")]
|
||||
};
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
import { export_json_to_excel } from "./export2excel";
|
||||
|
||||
function currentDate() {
|
||||
const d: Date = new Date();
|
||||
|
||||
return {
|
||||
year: d.getFullYear(),
|
||||
month: d.getMonth() + 1,
|
||||
day: d.getDate(),
|
||||
hour: d.getHours(),
|
||||
minu: d.getMinutes(),
|
||||
sec: d.getSeconds()
|
||||
};
|
||||
}
|
||||
|
||||
export { export_json_to_excel, currentDate };
|
@ -13,7 +13,11 @@ export default (): ModuleConfig => {
|
||||
// 文本预览
|
||||
() => import("./editor/preview.vue"),
|
||||
// 省市区选择 https://github.com/modood/Administrative-divisions-of-China
|
||||
() => import("./distpicker/index")
|
||||
() => import("./distpicker/index"),
|
||||
// 导入按钮
|
||||
() => import("./excel/import-btn.vue"),
|
||||
// 导出按钮
|
||||
() => import("./excel/export-btn")
|
||||
]
|
||||
};
|
||||
};
|
||||
|
@ -2,7 +2,8 @@ import { defineComponent, PropType } from "vue";
|
||||
import { useCrud } from "@cool-vue/crud";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { isRef, ref } from "vue";
|
||||
import { currentDate, export_json_to_excel } from "../utils";
|
||||
import { export_json_to_excel } from "./utils";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export default defineComponent({
|
||||
name: "cl-export-btn",
|
||||
@ -92,8 +93,7 @@ export default defineComponent({
|
||||
if (typeof props.filename === "function") {
|
||||
return await props?.filename();
|
||||
} else {
|
||||
const { year, month, day, hour, minu, sec } = currentDate();
|
||||
return props.filename || `报表(${year}-${month}-${day} ${hour}_${minu}_${sec})`;
|
||||
return props.filename || `报表(${dayjs().format("YYYY-MM-DD HH_mm_ss")})`;
|
||||
}
|
||||
}
|
||||
|
206
src/modules/extend/excel/import-btn.vue
Normal file
206
src/modules/extend/excel/import-btn.vue
Normal file
@ -0,0 +1,206 @@
|
||||
<template>
|
||||
<el-button :disabled="disabled" type="success" @click="open">导入</el-button>
|
||||
|
||||
<cl-form ref="Form">
|
||||
<template #slot-upload>
|
||||
<div class="upload">
|
||||
<div class="tips">
|
||||
<span>{{ tips }}</span>
|
||||
<el-button type="primary" text bg @click="download">下载模版</el-button>
|
||||
</div>
|
||||
|
||||
<div class="inner">
|
||||
<cl-upload
|
||||
drag
|
||||
:accept="accept"
|
||||
:disabled="disabled"
|
||||
type="file"
|
||||
:before-upload="onUpload"
|
||||
:size="[220, '100%']"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="progress" v-if="progress > 0">
|
||||
<el-progress type="dashboard" :percentage="progress" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</cl-form>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="cl-import-btn">
|
||||
import { useForm } from "@cool-vue/crud";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { reactive, ref } from "vue";
|
||||
import XLSX from "xlsx";
|
||||
|
||||
const props = defineProps({
|
||||
onConfig: Function,
|
||||
onSubmit: {
|
||||
type: Function,
|
||||
required: true
|
||||
},
|
||||
template: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
tips: {
|
||||
type: String,
|
||||
default: "请按照模版填写信息"
|
||||
},
|
||||
limitSize: {
|
||||
type: Number,
|
||||
default: 10
|
||||
},
|
||||
disabled: Boolean,
|
||||
accept: String
|
||||
});
|
||||
|
||||
const emit = defineEmits(["change"]);
|
||||
|
||||
const Form = useForm();
|
||||
|
||||
// 上传信息
|
||||
const upload = reactive({
|
||||
filename: "",
|
||||
data: []
|
||||
});
|
||||
|
||||
// 进度
|
||||
const progress = ref(0);
|
||||
|
||||
// 清空
|
||||
function clear() {
|
||||
progress.value = 0;
|
||||
upload.filename = "";
|
||||
upload.data = [];
|
||||
}
|
||||
|
||||
// 打开
|
||||
function open() {
|
||||
clear();
|
||||
|
||||
Form.value?.open({
|
||||
title: "导入",
|
||||
width: "800px",
|
||||
dialog: {
|
||||
"close-on-press-escape": false
|
||||
},
|
||||
items: [
|
||||
...(props.onConfig ? props.onConfig(Form) : []),
|
||||
{
|
||||
label: "",
|
||||
prop: "file",
|
||||
props: {
|
||||
labelWidth: "0"
|
||||
},
|
||||
component: {
|
||||
name: "slot-upload"
|
||||
}
|
||||
}
|
||||
],
|
||||
op: {
|
||||
saveButtonText: "提交"
|
||||
},
|
||||
on: {
|
||||
submit(data, { done, close }) {
|
||||
if (!upload.filename) {
|
||||
done();
|
||||
return ElMessage.error("请选择文件");
|
||||
}
|
||||
|
||||
if (props.onSubmit) {
|
||||
props.onSubmit(
|
||||
{
|
||||
...data,
|
||||
list: upload.data
|
||||
},
|
||||
{ done, close, setProgress }
|
||||
);
|
||||
} else {
|
||||
console.error("cl-import-btn 未配置 onSubmit");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onUpload(raw: File, _: any, { next }: any) {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = (event: any) => {
|
||||
const { result } = event.target;
|
||||
|
||||
const workbook = XLSX.read(result, { type: "binary" });
|
||||
|
||||
let data: any[] = [];
|
||||
for (const sheet in workbook.Sheets) {
|
||||
if (workbook.Sheets.hasOwnProperty(sheet)) {
|
||||
data = data.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
upload.data = data;
|
||||
upload.filename = raw.name;
|
||||
|
||||
console.log(upload.filename, upload.data);
|
||||
|
||||
emit("change", data);
|
||||
};
|
||||
reader.readAsBinaryString(raw);
|
||||
|
||||
next();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 下载模版
|
||||
function download() {
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", props.template);
|
||||
link.setAttribute("download", "");
|
||||
link.click();
|
||||
}
|
||||
|
||||
// 设置进度值
|
||||
function setProgress(val: string) {
|
||||
progress.value = parseInt(val);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.upload {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.inner {
|
||||
width: 100%;
|
||||
|
||||
:deep(.cl-upload) {
|
||||
.cl-upload__footer,
|
||||
.cl-upload__list,
|
||||
.el-upload,
|
||||
.is-drag {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
|
||||
& > span {
|
||||
color: var(--el-color-warning);
|
||||
}
|
||||
}
|
||||
|
||||
.progress {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
@ -90,13 +90,8 @@ function sheet_from_array_of_arrays(data, opts) {
|
||||
r: R
|
||||
});
|
||||
|
||||
if (typeof cell.v === "number") cell.t = "n";
|
||||
else if (typeof cell.v === "boolean") cell.t = "b";
|
||||
else if (cell.v instanceof Date) {
|
||||
cell.t = "n";
|
||||
cell.z = XLSX.SSF._table[14];
|
||||
cell.v = datenum(cell.v);
|
||||
} else cell.t = "s";
|
||||
// 修改这里:无论原始类型是什么,都将单元格类型设置为 "s"
|
||||
cell.t = "s";
|
||||
|
||||
ws[cell_ref] = cell;
|
||||
}
|
67
yarn.lock
67
yarn.lock
@ -979,6 +979,14 @@ acorn@^8.5.0, acorn@^8.8.0:
|
||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
|
||||
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
|
||||
|
||||
adler-32@~1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/adler-32/-/adler-32-1.2.0.tgz#6a3e6bf0a63900ba15652808cb15c6813d1a5f25"
|
||||
integrity sha512-/vUqU/UY4MVeFsg+SsK6c+/05RZXIHZMGJA+PX5JyWI0ZRcBpupnRuPLU/NXXoFwMYCPCoxIfElM2eS+DUXCqQ==
|
||||
dependencies:
|
||||
exit-on-epipe "~1.0.1"
|
||||
printj "~1.1.0"
|
||||
|
||||
adler-32@~1.3.0:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/adler-32/-/adler-32-1.3.1.tgz#1dbf0b36dda0012189a32b3679061932df1821e2"
|
||||
@ -1155,7 +1163,7 @@ caniuse-lite@^1.0.30001449:
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001460.tgz#31d2e26f0a2309860ed3eff154e03890d9d851a7"
|
||||
integrity sha512-Bud7abqjvEjipUkpLs4D7gR0l8hBYBHoa+tGtKJHvT2AYzLp1z7EmVkUT4ERpVUfca8S2HGIVs883D8pUH1ZzQ==
|
||||
|
||||
cfb@~1.2.1:
|
||||
cfb@^1.1.4:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/cfb/-/cfb-1.2.2.tgz#94e687628c700e5155436dac05f74e08df23bc44"
|
||||
integrity sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==
|
||||
@ -1209,10 +1217,13 @@ clone@^2.1.1:
|
||||
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
|
||||
integrity sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==
|
||||
|
||||
codepage@~1.15.0:
|
||||
version "1.15.0"
|
||||
resolved "https://registry.yarnpkg.com/codepage/-/codepage-1.15.0.tgz#2e00519024b39424ec66eeb3ec07227e692618ab"
|
||||
integrity sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==
|
||||
codepage@~1.14.0:
|
||||
version "1.14.0"
|
||||
resolved "https://registry.yarnpkg.com/codepage/-/codepage-1.14.0.tgz#8cbe25481323559d7d307571b0fff91e7a1d2f99"
|
||||
integrity sha512-iz3zJLhlrg37/gYRWgEPkaFTtzmnEv1h+r7NgZum2lFElYQPi0/5bnmuDfODHxfp0INEfnRqyfyeIJDbb7ahRw==
|
||||
dependencies:
|
||||
commander "~2.14.1"
|
||||
exit-on-epipe "~1.0.1"
|
||||
|
||||
color-convert@^1.9.0:
|
||||
version "1.9.3"
|
||||
@ -1255,6 +1266,16 @@ commander@^2.20.0:
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
|
||||
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
|
||||
|
||||
commander@~2.14.1:
|
||||
version "2.14.1"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa"
|
||||
integrity sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==
|
||||
|
||||
commander@~2.17.1:
|
||||
version "2.17.1"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
|
||||
integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==
|
||||
|
||||
commist@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/commist/-/commist-1.1.0.tgz#17811ec6978f6c15ee4de80c45c9beb77cee35d5"
|
||||
@ -1293,7 +1314,7 @@ core-js@^3.21.1, core-js@^3.23.5:
|
||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.29.0.tgz#0273e142b67761058bcde5615c503c7406b572d6"
|
||||
integrity sha512-VG23vuEisJNkGl6XQmFJd3rEG/so/CNatqeE+7uZAwTSwFeB/qaO0be8xZYUNWprJ/GIwL8aMt9cj1kvbpTZhg==
|
||||
|
||||
crc-32@~1.2.0, crc-32@~1.2.1:
|
||||
crc-32@~1.2.0:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-1.2.2.tgz#3cad35a934b8bf71f25ca524b6da51fb7eace2ff"
|
||||
integrity sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==
|
||||
@ -1763,6 +1784,11 @@ eventemitter3@^2.0.3:
|
||||
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-2.0.3.tgz#b5e1079b59fb5e1ba2771c0a993be060a58c99ba"
|
||||
integrity sha512-jLN68Dx5kyFHaePoXWPsCGW5qdyZQtLYHkxkg02/Mz6g0kYpDx4FyP6XfArhQdlOC4b8Mv+EMxPo/8La7Tzghg==
|
||||
|
||||
exit-on-epipe@~1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz#0bdd92e87d5285d267daa8171d0eb06159689692"
|
||||
integrity sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==
|
||||
|
||||
ext@^1.1.2:
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/ext/-/ext-1.7.0.tgz#0ea4383c0103d60e70be99e9a7f11027a33c4f5f"
|
||||
@ -1818,6 +1844,11 @@ fastq@^1.6.0:
|
||||
dependencies:
|
||||
reusify "^1.0.4"
|
||||
|
||||
fflate@^0.3.8:
|
||||
version "0.3.11"
|
||||
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.3.11.tgz#2c440d7180fdeb819e64898d8858af327b042a5d"
|
||||
integrity sha512-Rr5QlUeGN1mbOHlaqcSYMKVpPbgLy0AWT/W0EHxA6NGI12yO1jpoui2zBBvU2G824ltM6Ut8BFgfHSBGfkmS0A==
|
||||
|
||||
file-entry-cache@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
|
||||
@ -2807,6 +2838,11 @@ prettier@^2.8.4:
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
|
||||
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==
|
||||
|
||||
printj@~1.1.0:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/printj/-/printj-1.1.2.tgz#d90deb2975a8b9f600fb3a1c94e3f4c53c78a222"
|
||||
integrity sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==
|
||||
|
||||
prismjs@^1.23.0:
|
||||
version "1.29.0"
|
||||
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
|
||||
@ -3490,15 +3526,18 @@ ws@~8.11.0:
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.11.0.tgz#6a0d36b8edfd9f96d8b25683db2f8d7de6e8e143"
|
||||
integrity sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==
|
||||
|
||||
xlsx@^0.18.5:
|
||||
version "0.18.5"
|
||||
resolved "https://registry.yarnpkg.com/xlsx/-/xlsx-0.18.5.tgz#16711b9113c848076b8a177022799ad356eba7d0"
|
||||
integrity sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==
|
||||
xlsx@0.16.9:
|
||||
version "0.16.9"
|
||||
resolved "https://registry.yarnpkg.com/xlsx/-/xlsx-0.16.9.tgz#dacd5bb46bda6dd3743940c9c3dc1e2171826256"
|
||||
integrity sha512-gxi1I3EasYvgCX1vN9pGyq920Ron4NO8PNfhuoA3Hpq6Y8f0ECXiy4OLrK4QZBnj1jx3QD+8Fq5YZ/3mPZ5iXw==
|
||||
dependencies:
|
||||
adler-32 "~1.3.0"
|
||||
cfb "~1.2.1"
|
||||
codepage "~1.15.0"
|
||||
crc-32 "~1.2.1"
|
||||
adler-32 "~1.2.0"
|
||||
cfb "^1.1.4"
|
||||
codepage "~1.14.0"
|
||||
commander "~2.17.1"
|
||||
crc-32 "~1.2.0"
|
||||
exit-on-epipe "~1.0.1"
|
||||
fflate "^0.3.8"
|
||||
ssf "~0.11.2"
|
||||
wmf "~1.0.1"
|
||||
word "~0.3.0"
|
||||
|
Loading…
Reference in New Issue
Block a user