Commit 29461a856826fbb7726848982387ea78f8573754

Authored by vben
1 parent bae53f3e

fix: file upload key loss #120

.env.development
... ... @@ -14,5 +14,8 @@ VITE_DROP_CONSOLE = false
14 14 # Basic interface address SPA
15 15 VITE_GLOB_API_URL=/api
16 16  
  17 +# File upload address, optional
  18 +VITE_GLOB_UPLOAD_URL=/upload
  19 +
17 20 # Interface prefix
18 21 VITE_GLOB_API_URL_PREFIX=
... ...
.env.production
... ... @@ -13,6 +13,10 @@ VITE_BUILD_GZIP = false
13 13 # Basic interface address SPA
14 14 VITE_GLOB_API_URL=/api
15 15  
  16 +# File upload address, optional
  17 +# It can be forwarded by nginx or write the actual address directly
  18 +VITE_GLOB_UPLOAD_URL=/upload
  19 +
16 20 # Interface prefix
17 21 VITE_GLOB_API_URL_PREFIX=
18 22  
... ...
CHANGELOG.zh_CN.md
... ... @@ -11,6 +11,7 @@
11 11 - i18n 支持 vscode `i18n-ally`插件
12 12 - 新增多级路由缓存示例
13 13 - 打包代码拆分(试验)
  14 +- 提取上传地址到全局变量,打包可以动态配置
14 15  
15 16 ### ⚡ Performance Improvements
16 17  
... ... @@ -23,6 +24,7 @@
23 24 - 升级`ant-design-vue`到`2.0.0-rc.3`
24 25 - 重新引入`vueuse`
25 26 - 移除 route meta 内的`afterCloseLoading`属性
  27 +- 文档更新
26 28  
27 29 ### 🐛 Bug Fixes
28 30  
... ... @@ -31,6 +33,7 @@
31 33 - 修复顶部菜单宽度计算问题
32 34 - 修复表格 tabSetting 问题
33 35 - 修复文件上传删除失效
  36 +- 修复表格行编辑保存错误问题
34 37  
35 38 ## 2.0.0-rc.12 (2020-11-30)
36 39  
... ...
src/api/sys/upload.ts
1 1 import { UploadApiResult } from './model/uploadModel';
2 2 import { defHttp } from '/@/utils/http/axios';
3 3 import { UploadFileParams } from '/@/utils/http/axios/types';
  4 +import { useGlobSetting } from '/@/hooks/setting';
4 5  
5   -enum Api {
6   - UPLOAD_URL = '/upload',
7   -}
  6 +const { uploadUrl = '' } = useGlobSetting();
8 7  
9 8 /**
10 9 * @description: Upload interface
... ... @@ -15,7 +14,7 @@ export function uploadApi(
15 14 ) {
16 15 return defHttp.uploadFile<UploadApiResult>(
17 16 {
18   - url: Api.UPLOAD_URL,
  17 + url: uploadUrl,
19 18 onUploadProgress,
20 19 },
21 20 params
... ...
src/components/Excel/src/Export2Excel.ts
... ... @@ -31,6 +31,7 @@ export function jsonToSheetXlsx&lt;T = any&gt;({
31 31 writeFile(workbook, filename, write2excelOpts);
32 32 /* at this point, out.xlsb will have been downloaded */
33 33 }
  34 +
34 35 export function aoaToSheetXlsx<T = any>({
35 36 data,
36 37 header,
... ...
src/components/Excel/src/ImportExcel.vue
... ... @@ -17,7 +17,7 @@
17 17 import type { ExcelData } from './types';
18 18 export default defineComponent({
19 19 name: 'ImportExcel',
20   - emits: ['success'],
  20 + emits: ['success', 'error'],
21 21 setup(_, { emit }) {
22 22 const inputRef = ref<HTMLInputElement | null>(null);
23 23 const loadingRef = ref<Boolean>(false);
... ... @@ -82,6 +82,7 @@
82 82 resolve('');
83 83 } catch (error) {
84 84 reject(error);
  85 + emit('error');
85 86 } finally {
86 87 loadingRef.value = false;
87 88 }
... ...
src/components/Excel/src/types.ts
... ... @@ -17,6 +17,7 @@ export interface JsonToSheet&lt;T = any&gt; {
17 17 json2sheetOpts?: JSON2SheetOpts;
18 18 write2excelOpts?: WritingOptions;
19 19 }
  20 +
20 21 export interface AoAToSheet<T = any> {
21 22 data: T[][];
22 23 header?: T[];
... ...
src/components/Form/src/types/index.ts
... ... @@ -93,7 +93,6 @@ export type ComponentType =
93 93 | 'SelectOption'
94 94 | 'TreeSelect'
95 95 | 'Transfer'
96   - // | 'Radio'
97 96 | 'RadioButtonGroup'
98 97 | 'RadioGroup'
99 98 | 'Checkbox'
... ...
src/components/Menu/src/BasicMenu.tsx
... ... @@ -190,6 +190,7 @@ export default defineComponent({
190 190 const { appendClass } = props;
191 191 const isAppendActiveCls =
192 192 appendClass && level === 1 && menu.path === unref(currentParentPath);
  193 +
193 194 const levelCls = [
194 195 `${prefixCls}-item__level${level}`,
195 196 ` ${menuState.theme} `,
... ...
src/components/Upload/src/FileList.tsx
... ... @@ -38,9 +38,9 @@ export default defineComponent({
38 38 </tr>
39 39 </thead>
40 40 <tbody>
41   - {dataSource.map((record = {}) => {
  41 + {dataSource.map((record = {}, index) => {
42 42 return (
43   - <tr class="file-table-tr" key={record.uuid}>
  43 + <tr class="file-table-tr" key={`${index + record.name || ''}`}>
44 44 {columnList.map((item) => {
45 45 const { dataIndex = '', customRender, align = 'center' } = item;
46 46 const render = customRender && isFunction(customRender);
... ...
src/hooks/setting/index.ts
... ... @@ -18,6 +18,7 @@ const {
18 18 VITE_GLOB_API_URL,
19 19 VITE_GLOB_APP_SHORT_NAME,
20 20 VITE_GLOB_API_URL_PREFIX,
  21 + VITE_GLOB_UPLOAD_URL,
21 22 } = ENV;
22 23  
23 24 if (!reg.test(VITE_GLOB_APP_SHORT_NAME)) {
... ... @@ -33,6 +34,7 @@ export const useGlobSetting = (): Readonly&lt;GlobConfig&gt; =&gt; {
33 34 apiUrl: VITE_GLOB_API_URL,
34 35 shortName: VITE_GLOB_APP_SHORT_NAME,
35 36 urlPrefix: VITE_GLOB_API_URL_PREFIX,
  37 + uploadUrl: VITE_GLOB_UPLOAD_URL,
36 38 };
37 39 return glob as Readonly<GlobConfig>;
38 40 };
... ...
src/types/config.d.ts
... ... @@ -129,6 +129,7 @@ export interface GlobConfig {
129 129 title: string;
130 130 // 项目路径
131 131 apiUrl: string;
  132 + uploadUrl?: string;
132 133 urlPrefix?: string;
133 134 shortName: string;
134 135 }
... ... @@ -139,6 +140,7 @@ export interface GlobEnvConfig {
139 140 VITE_GLOB_API_URL: string;
140 141 VITE_GLOB_API_URL_PREFIX?: string;
141 142 VITE_GLOB_APP_SHORT_NAME: string;
  143 + VITE_GLOB_UPLOAD_URL?: string;
142 144 }
143 145  
144 146 interface GlobWrap {
... ...
src/views/demo/excel/ArrayExport.vue
... ... @@ -11,11 +11,11 @@
11 11 <script lang="ts">
12 12 import { defineComponent } from 'vue';
13 13 import { BasicTable } from '/@/components/Table';
14   - import { aoaToSheetXlsx, ExportExcelModel } from '/@/components/Excel';
  14 + import { aoaToSheetXlsx } from '/@/components/Excel';
15 15 import { arrHeader, arrData, columns, data } from './data';
16 16  
17 17 export default defineComponent({
18   - components: { BasicTable, ExportExcelModel },
  18 + components: { BasicTable },
19 19 setup() {
20 20 function aoaToExcel() {
21 21 // 保证data顺序与header一致
... ...
src/views/demo/excel/JsonExport.vue
... ... @@ -12,11 +12,11 @@
12 12 <script lang="ts">
13 13 import { defineComponent } from 'vue';
14 14 import { BasicTable } from '/@/components/Table';
15   - import { jsonToSheetXlsx, ExportExcelModel } from '/@/components/Excel';
  15 + import { jsonToSheetXlsx } from '/@/components/Excel';
16 16 import { columns, data } from './data';
17 17  
18 18 export default defineComponent({
19   - components: { BasicTable, ExportExcelModel },
  19 + components: { BasicTable },
20 20 setup() {
21 21 function defaultHeader() {
22 22 // 默认Object.keys(data[0])作为header
... ... @@ -25,6 +25,7 @@
25 25 filename: '使用key作为默认头部.xlsx',
26 26 });
27 27 }
  28 +
28 29 function customHeader() {
29 30 jsonToSheetXlsx({
30 31 data,
... ...