Skip to content

Commit

Permalink
fix(components): [draggable-modal] close after route switch
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Feb 17, 2022
1 parent ab5dfc1 commit 6101460
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 417 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
last 2 versions
not dead
not ie 11
chrome 79
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
},
"dependencies": {
"@ant-design/icons-vue": "^6.0.1",
"@vueuse/core": "^7.5.5",
"@vueuse/core": "^7.6.2",
"ant-design-vue": "3.0.0-beta.9",
"axios": "^0.25.0",
"core-js": "^3.21.0",
"axios": "^0.26.0",
"core-js": "^3.21.1",
"dayjs": "^1.10.7",
"file-saver": "^2.0.5",
"lodash-es": "^4.17.21",
Expand All @@ -41,47 +41,47 @@
"qs": "^6.10.3",
"socket.io-client": "4.4.1",
"sortablejs": "^1.14.0",
"vue": "^3.2.29",
"vue": "^3.2.31",
"vue-i18n": "^9.2.0-beta.30",
"vue-router": "^4.0.12",
"xlsx": "^0.18.0"
"xlsx": "^0.18.2"
},
"devDependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0",
"@types/lodash-es": "^4.17.5",
"@types/node": "^17.0.14",
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@types/lodash-es": "^4.17.6",
"@types/node": "^17.0.18",
"@types/webpack-env": "^1.16.3",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"@vue/cli-plugin-babel": "^5.0.0-rc.2",
"@vue/cli-plugin-eslint": "^5.0.0-rc.2",
"@vue/cli-plugin-router": "^5.0.0-rc.2",
"@vue/cli-plugin-typescript": "^5.0.0-rc.2",
"@vue/cli-plugin-vuex": "^5.0.0-rc.2",
"@vue/cli-service": "^5.0.0-rc.2",
"@vue/compiler-sfc": "^3.2.29",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"@vue/cli-plugin-babel": "^5.0.0-rc.3",
"@vue/cli-plugin-eslint": "^5.0.0-rc.3",
"@vue/cli-plugin-router": "^5.0.0-rc.3",
"@vue/cli-plugin-typescript": "^5.0.0-rc.3",
"@vue/cli-plugin-vuex": "^5.0.0-rc.3",
"@vue/cli-service": "^5.0.0-rc.3",
"@vue/compiler-sfc": "^3.2.31",
"@vue/eslint-config-typescript": "^10.0.0",
"babel-plugin-import": "^1.13.3",
"commitizen": "^4.2.4",
"compression-webpack-plugin": "^9.2.0",
"conventional-changelog-cli": "^2.2.2",
"eslint": "^8.8.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.4.0",
"eslint-plugin-vue": "^8.4.1",
"husky": "^7.0.4",
"less": "^4.1.2",
"less-loader": "10.2.0",
"lint-staged": "^12.3.3",
"lint-staged": "^12.3.4",
"path-browserify": "^1.0.1",
"postcss-html": "^1.3.0",
"prettier": "^2.5.1",
"stylelint": "^14.3.0",
"stylelint": "^14.5.1",
"stylelint-config-html": "^1.0.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^6.0.0",
"stylelint-config-standard": "^24.0.0",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0",
"svg-sprite-loader": "^6.0.11",
"typescript": "^4.5.5",
Expand Down
2 changes: 1 addition & 1 deletion src/components/basic/excel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export { useExportExcelModal } from './src/ExportExcelModal';
export const ImpExcel = withInstall(impExcel);
// export const ExpExcelModal = withInstall(expExcelModal);
export * from './src/typing';
export { jsonToSheetXlsx, aoaToSheetXlsx } from './src/Export2Excel';
export * from './src/Export2Excel';
4 changes: 1 addition & 3 deletions src/components/basic/excel/src/Export2Excel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import xlsx from 'xlsx';
import { utils, writeFile } from 'xlsx';
import type { WorkBook } from 'xlsx';
import type { JsonToSheet, AoAToSheet } from './typing';

const { utils, writeFile } = xlsx;

const DEF_FILE_NAME = 'excel-list.xlsx';

export function jsonToSheetXlsx<T = any>({
Expand Down
17 changes: 9 additions & 8 deletions src/components/basic/excel/src/ImportExcel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
</template>
<script lang="ts">
import { defineComponent, ref, unref } from 'vue';
import XLSX from 'xlsx';
import { read, utils } from 'xlsx';
import type { WorkSheet, WorkBook } from 'xlsx';
import { dateUtil } from '@/utils/dateUtil';
import type { ExcelData } from './typing';
Expand All @@ -40,20 +41,20 @@
/**
* @description: 第一行作为头部
*/
function getHeaderRow(sheet: XLSX.WorkSheet) {
function getHeaderRow(sheet: WorkSheet) {
if (!sheet || !sheet['!ref']) return [];
const headers: string[] = [];
// A3:B7=>{s:{c:0, r:2}, e:{c:1, r:6}}
const range = XLSX.utils.decode_range(sheet['!ref']);
const range = utils.decode_range(sheet['!ref']);
const R = range.s.r;
/* start in the first row */
for (let C = range.s.c; C <= range.e.c; ++C) {
/* walk every column in the range */
const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })];
const cell = sheet[utils.encode_cell({ c: C, r: R })];
/* find the cell in the first row */
let hdr = 'UNKNOWN ' + C; // <-- replace with your desired default
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell);
if (cell && cell.t) hdr = utils.format_cell(cell);
headers.push(hdr);
}
return headers;
Expand All @@ -62,13 +63,13 @@
/**
* @description: 获得excel数据
*/
function getExcelData(workbook: XLSX.WorkBook) {
function getExcelData(workbook: WorkBook) {
const excelData: ExcelData[] = [];
const { dateFormat, timeZone } = props;
for (const sheetName of workbook.SheetNames) {
const worksheet = workbook.Sheets[sheetName];
const header: string[] = getHeaderRow(worksheet);
let results = XLSX.utils.sheet_to_json(worksheet, {
let results = utils.sheet_to_json(worksheet, {
raw: true,
dateNF: dateFormat, //Not worked
}) as object[];
Expand Down Expand Up @@ -107,7 +108,7 @@
reader.onload = async (e) => {
try {
const data = e.target && e.target.result;
const workbook = XLSX.read(data, { type: 'array', cellDates: true });
const workbook = read(data, { type: 'array', cellDates: true });
// console.log(workbook);
/* DO SOMETHING WITH workbook HERE */
const excelData = getExcelData(workbook);
Expand Down
4 changes: 4 additions & 0 deletions src/components/core/draggable-modal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

<script lang="ts" setup>
import { ref, watch, nextTick } from 'vue';
import { useRoute } from 'vue-router';
import { Modal, Space } from 'ant-design-vue';
// import { modalProps } from 'ant-design-vue/es/modal/Modal';
import { CloseOutlined, FullscreenOutlined, FullscreenExitOutlined } from '@ant-design/icons-vue';
Expand Down Expand Up @@ -66,6 +67,7 @@
const emit = defineEmits(['update:visible', 'update:fullscreen', 'ok', 'cancel']);
const route = useRoute();
const visibleModel = useVModel(props, 'visible');
const fullscreenModel = ref(props.fullscreen);
const innerWidth = ref('');
Expand Down Expand Up @@ -260,6 +262,8 @@
initDrag();
}
});
watch(() => route.fullPath, closeModal);
</script>

<style lang="less">
Expand Down
14 changes: 7 additions & 7 deletions src/utils/Export2Excel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { saveAs } from 'file-saver';
import XLSX from 'xlsx';
import { SSF, utils, write } from 'xlsx';

function generateArray(table) {
var out = [];
Expand Down Expand Up @@ -84,7 +84,7 @@ function sheet_from_array_of_arrays(data, opts) {
v: data[R][C],
};
if (cell.v == null) continue;
var cell_ref = XLSX.utils.encode_cell({
var cell_ref = utils.encode_cell({
c: C,
r: R,
});
Expand All @@ -93,14 +93,14 @@ function sheet_from_array_of_arrays(data, opts) {
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.z = SSF._table[14];
cell.v = datenum(cell.v);
} else cell.t = 's';

ws[cell_ref] = cell;
}
}
if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
if (range.s.c < 10000000) ws['!ref'] = utils.encode_range(range);
return ws;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ export function export_table_to_excel(id) {
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;

var wbout = XLSX.write(wb, {
var wbout = write(wb, {
bookType: 'xlsx',
bookSST: false,
type: 'binary',
Expand Down Expand Up @@ -176,7 +176,7 @@ export function export_json_to_excel({
if (merges.length > 0) {
if (!ws['!merges']) ws['!merges'] = [];
merges.forEach((item) => {
ws['!merges'].push(XLSX.utils.decode_range(item));
ws['!merges'].push(utils.decode_range(item));
});
}

Expand Down Expand Up @@ -217,7 +217,7 @@ export function export_json_to_excel({
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;

var wbout = XLSX.write(wb, {
var wbout = write(wb, {
bookType: bookType,
bookSST: false,
type: 'binary',
Expand Down
Loading

0 comments on commit 6101460

Please sign in to comment.