Commit 91e004e21148c38e572cfbb6b75f0a6f353c15b6

Authored by vben
1 parent 22088e82

fix(upload): fix maxNumber not work #240

CHANGELOG.zh_CN.md
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 ### 🐛 Bug Fixes 3 ### 🐛 Bug Fixes
4 4
5 - 修复菜单在 hmr 时数据被置空 5 - 修复菜单在 hmr 时数据被置空
  6 +- 修复 Upload 组件 maxNumber 失效问题
6 7
7 ## 2.0.0-rc.18 (2021-02-05) 8 ## 2.0.0-rc.18 (2021-02-05)
8 9
build/config/themeConfig.ts
1 import { generate } from '@ant-design/colors'; 1 import { generate } from '@ant-design/colors';
  2 +
2 export const primaryColor = '#0084f4'; 3 export const primaryColor = '#0084f4';
3 4
4 export const themeMode = 'light'; 5 export const themeMode = 'light';
src/components/Upload/src/BasicUpload.vue
@@ -20,7 +20,12 @@ @@ -20,7 +20,12 @@
20 </Tooltip> 20 </Tooltip>
21 </a-button-group> 21 </a-button-group>
22 22
23 - <UploadModal v-bind="bindValue" @register="registerUploadModal" @change="handleChange" /> 23 + <UploadModal
  24 + v-bind="bindValue"
  25 + :previewFileList="fileListRef"
  26 + @register="registerUploadModal"
  27 + @change="handleChange"
  28 + />
24 29
25 <UploadPreviewModal 30 <UploadPreviewModal
26 :value="fileListRef" 31 :value="fileListRef"
src/components/Upload/src/UploadModal.vue
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
42 </BasicModal> 42 </BasicModal>
43 </template> 43 </template>
44 <script lang="ts"> 44 <script lang="ts">
45 - import { defineComponent, reactive, ref, toRefs, unref, computed } from 'vue'; 45 + import { defineComponent, reactive, ref, toRefs, unref, computed, PropType } from 'vue';
46 import { Upload, Alert } from 'ant-design-vue'; 46 import { Upload, Alert } from 'ant-design-vue';
47 import { BasicModal, useModalInner } from '/@/components/Modal'; 47 import { BasicModal, useModalInner } from '/@/components/Modal';
48 // import { BasicTable, useTable } from '/@/components/Table'; 48 // import { BasicTable, useTable } from '/@/components/Table';
@@ -63,7 +63,13 @@ @@ -63,7 +63,13 @@
63 import { useI18n } from '/@/hooks/web/useI18n'; 63 import { useI18n } from '/@/hooks/web/useI18n';
64 export default defineComponent({ 64 export default defineComponent({
65 components: { BasicModal, Upload, Alert, FileList }, 65 components: { BasicModal, Upload, Alert, FileList },
66 - props: basicProps, 66 + props: {
  67 + ...basicProps,
  68 + previewFileList: {
  69 + type: Array as PropType<string[]>,
  70 + default: () => [],
  71 + },
  72 + },
67 emits: ['change', 'register'], 73 emits: ['change', 'register'],
68 setup(props, { emit }) { 74 setup(props, { emit }) {
69 const { t } = useI18n(); 75 const { t } = useI18n();
@@ -206,7 +212,7 @@ @@ -206,7 +212,7 @@
206 // 点击开始上传 212 // 点击开始上传
207 async function handleStartUpload() { 213 async function handleStartUpload() {
208 const { maxNumber } = props; 214 const { maxNumber } = props;
209 - if (fileListRef.value.length > maxNumber) { 215 + if ((fileListRef.value.length + props.previewFileList?.length ?? 0) > maxNumber) {
210 return createMessage.warning(t('component.upload.maxNumber', [maxNumber])); 216 return createMessage.warning(t('component.upload.maxNumber', [maxNumber]));
211 } 217 }
212 try { 218 try {
src/components/Upload/src/data.tsx
@@ -156,7 +156,7 @@ export function createPreviewActionColumn({ @@ -156,7 +156,7 @@ export function createPreviewActionColumn({
156 // onClick: handlePreview.bind(null, record), 156 // onClick: handlePreview.bind(null, record),
157 // }); 157 // });
158 // } 158 // }
159 - return <TableAction actions={actions} />; 159 + return <TableAction actions={actions} outside={true} />;
160 }, 160 },
161 }; 161 };
162 } 162 }