Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(select): 【全部】选项文案需要支持自定义 #2208

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from
17 changes: 15 additions & 2 deletions packages/select/src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default defineComponent({
scrollHeight: PropTypes.number.def(204), // 最大高度
minHeight: PropTypes.number, // 最小高度
showAll: PropTypes.bool.def(false), // 全部
allOptionText: PropTypes.string.def(''), // 全部选项文本
allOptionId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), // 全部选项ID
showSelectAll: PropTypes.bool.def(false), // 全选
popoverMinWidth: PropTypes.number.def(0), // popover最小宽度
Expand Down Expand Up @@ -165,6 +166,9 @@ export default defineComponent({
} = toRefs(props);

const virtualRenderRef = ref(null);
const displayAllText = computed(() => {
return props.allOptionText;
});
const localNoDataText = computed(() => {
if (props.noDataText === undefined) {
return t.value.noData;
Expand Down Expand Up @@ -850,6 +854,7 @@ export default defineComponent({
popoverConfig,
isAllSelected,
isAll,
displayAllText,
focusInput,
setHover,
cancelHover,
Expand Down Expand Up @@ -950,6 +955,14 @@ export default defineComponent({
</li>
);
};
// 全部icon支持自定义
const renderAllIcon = () => {
return this.$slots?.allOptionIcon?.() || <TextAll class='select-all-icon' />;
};
// 全部选项文案支持自定义
const renderAllText = () => {
return <span>{this.displayAllText || this.t.all}</span>;
};
// 全部
const renderAll = () => {
if (!this.isShowAll) return;
Expand All @@ -962,8 +975,8 @@ export default defineComponent({
]}
onClick={this.toggleAll}
>
<TextAll class='select-all-icon' />
<span>{this.t.all}</span>
{renderAllIcon()}
{renderAllText()}
</div>
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/upload/src/upload-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Progress from '@bkui-vue/progress';
import { classes } from '@bkui-vue/shared';

import uploadProps from './props';
import { CLASS_PREFIX, EThemes, UploadFile } from './upload.type';
import { CLASS_PREFIX, EThemes, UploadFile, UploadFiles } from './upload.type';

export default defineComponent({
name: 'UploadList',
Expand Down Expand Up @@ -70,8 +70,8 @@ export default defineComponent({
return `${size.toFixed(2)}${uints[index]}`;
}

function handleReview(file: UploadFile, e: MouseEvent) {
emit('preview', file, e);
function handlePreview(file: UploadFile, files: UploadFiles, e: MouseEvent) {
emit('preview', file, files, e);
}

function handleRemove(file: UploadFile, e: MouseEvent) {
Expand Down Expand Up @@ -128,7 +128,7 @@ export default defineComponent({
{isShowPreview.value && (
<Eye
class='action-icon'
onClick={e => handleReview(file, e)}
onClick={e => handlePreview(file, props.files, e)}
/>
)}
<Del
Expand Down
6 changes: 3 additions & 3 deletions packages/upload/src/upload-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export default defineComponent({
e.preventDefault();
}

function handleReview(file: UploadFile, e: MouseEvent) {
emit('preview', file, e);
function handlePreview(file: UploadFile, e: MouseEvent) {
emit('preview', file, [file], e);

e.stopPropagation();
e.preventDefault();
Expand Down Expand Up @@ -222,7 +222,7 @@ export default defineComponent({
{isShowPreview.value && (
<Eye
class='action-icon'
onClick={e => handleReview(file, e)}
onClick={e => handlePreview(file, e)}
/>
)}
<Del
Expand Down
4 changes: 2 additions & 2 deletions packages/upload/src/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export default defineComponent({
}
}

function handlePreview(file: UploadFile) {
emit('preview', file);
function handlePreview(file: UploadFile, files?: UploadFile[]) {
emit('preview', file, files);
}

function handleRetry(file: UploadFile) {
Expand Down
13 changes: 13 additions & 0 deletions site/views/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ const propsJson: IPropsTableItem[] = [
desc: '是否展示全部',
optional: ['true', 'false'],
},
{
name: 'allOptionText',
type: 'string',
default: '全部',
desc: 'showAll为true时,全部选项的文本内容',
optional: [],
},
{
name: 'allOptionId',
type: 'string|number',
Expand Down Expand Up @@ -489,6 +496,12 @@ const selectSlots = [
default: null,
desc: '标签内容插槽(multiple-mode=“tag” 生效)',
},
{
name: 'allOptionIcon',
type: 'Slot',
default: null,
desc: '全部选项icon插槽(showAll=true时生效)',
},
];
const selectExpose = [
{
Expand Down
21 changes: 16 additions & 5 deletions site/views/upload/demo/preview-image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:files="files"
:handle-res-code="handleRes"
:is-show-preview="true"
:multiple="false"
:multiple="true"
:url="'https://jsonplaceholder.typicode.com/posts/'"
theme="picture"
with-credentials
Expand All @@ -31,11 +31,22 @@

import BkUpload from '@bkui-vue/upload';

import babyqImgUrl from '../../../imgs/babyq.png';
import babyImgUrl from '../../../imgs/babyq.png';
import dovImgUlr from '../../../imgs/dov.png';
import qqImageUrl from '../../../imgs/qq.png';

const files = ref([
{
url: babyqImgUrl,
name: 'baby',
url: babyImgUrl,
},
{
name: 'qq',
url: qqImageUrl,
},
{
name: 'dov',
url: dovImgUlr,
},
]);
const previewTitle = ref('图片预览');
Expand All @@ -53,13 +64,13 @@
return false;
};

const handlePreview = async file => {
const handlePreview = async (file, fileList) => {
if (!file.url) {
file.url = await getBase64(file);
}
previewImage.value = file.url;
previewVisible.value = true;
previewTitle.value = file.name || file.url.substring(file.url.lastIndexOf('/') + 1);
previewVisible.value = true;
};

const getBase64 = file => {
Expand Down
7 changes: 7 additions & 0 deletions site/views/upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ const uploadEvents: IPropsTableItem[] = [
desc: '文件上传成功后,点击删除文件触发的事件 ',
optional: ['file(删除的哪个文件对象)', 'fileList(删除后的文件列表)'],
},
{
name: 'preview',
type: 'Function',
default: null,
desc: '文件上传成功后,点击预览文件触发的事件 ',
optional: ['file(预览的哪个文件对象)', 'fileList(预览的文件列表)'],
},
];

const uploadSlots: IPropsTableItem[] = [
Expand Down