Former-commit-id: ef52f59717bcaddabd61386caaa18dc4aee7fbae
This commit is contained in:
april
2023-08-31 17:13:27 +08:00
6 changed files with 59 additions and 51 deletions

View File

@@ -1,5 +1,4 @@
<template> <template>
<div>
<el-select <el-select
v-model="selectedValue" v-model="selectedValue"
:placeholder="placeholder" :placeholder="placeholder"
@@ -14,7 +13,6 @@
:value="option.value" :value="option.value"
/> />
</el-select> </el-select>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -29,8 +27,7 @@ const props = defineProps({
required: true, required: true,
}, },
modelValue: { modelValue: {
type: String, type: [String, Number],
default: "",
}, },
placeholder: { placeholder: {
type: String, type: String,
@@ -46,9 +43,24 @@ const emits = defineEmits(["update:modelValue"]); // 父组件监听事件,同
const options: Ref<OptionType[]> = ref([]); // 字典下拉数据源 const options: Ref<OptionType[]> = ref([]); // 字典下拉数据源
const selectedValue = computed(() => props.modelValue.toString()); // 将父组件的值统一转化String和下拉数据源进行比较避免值的类型不一致导致回显失败 const selectedValue = ref<string | number | undefined>();
function handleChange(val?: string) { watch([options, () => props.modelValue], ([newOptions, newModelValue]) => {
if (newOptions.length === 0) return; // 下拉数据源加载未完成不回显
if (newModelValue == undefined) {
selectedValue.value = undefined;
return;
}
if (typeof newOptions[0].value === "number") {
selectedValue.value = Number(newModelValue);
} else if (typeof newOptions[0].value === "string") {
selectedValue.value = String(newModelValue);
} else {
selectedValue.value = newModelValue;
}
});
function handleChange(val?: string | number | undefined) {
emits("update:modelValue", val); emits("update:modelValue", val);
} }

View File

@@ -8,8 +8,8 @@
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
:http-request="uploadFile" :http-request="uploadFile"
> >
<img v-if="imgUrl" :src="imgUrl" class="single" /> <img v-if="imgUrl" :src="imgUrl" class="single-uploader__image" />
<el-icon v-else class="single-uploader-icon"><i-ep-plus /></el-icon> <el-icon v-else class="single-uploader__icon"><i-ep-plus /></el-icon>
</el-upload> </el-upload>
</template> </template>
@@ -49,33 +49,29 @@ function handleBeforeUpload(file: UploadRawFile) {
} }
</script> </script>
<style scoped> <style scoped lang="scss">
.single-uploader .single { .single-uploader {
overflow: hidden;
cursor: pointer;
border: 1px var(--el-border-color) solid;
border-radius: 6px;
&:hover {
border-color: var(--el-color-primary);
}
&__image {
display: block; display: block;
width: 178px; width: 178px;
height: 178px; height: 178px;
} }
</style>
<style> &___icon {
.single-uploader .el-upload {
position: relative;
overflow: hidden;
cursor: pointer;
border: 1px dashed var(--el-border-color);
border-radius: 6px;
transition: var(--el-transition-duration-fast);
}
.single-uploader .el-upload:hover {
border-color: var(--el-color-primary);
}
.el-icon.single-uploader-icon {
width: 178px; width: 178px;
height: 178px; height: 178px;
font-size: 28px; font-size: 28px;
color: #8c939d; color: #8c939d;
text-align: center; text-align: center;
} }
}
</style> </style>

View File

@@ -7,7 +7,7 @@ const appStore = useAppStore();
* 左侧菜单栏显示/隐藏 * 左侧菜单栏显示/隐藏
*/ */
function toggleSideBar() { function toggleSideBar() {
appStore.toggleSidebar(true); appStore.toggleSidebar();
} }
</script> </script>

View File

@@ -72,7 +72,7 @@ function handleOutsideClick() {
} }
function toggleSideBar() { function toggleSideBar() {
appStore.toggleSidebar(true); appStore.toggleSidebar();
} }
</script> </script>

View File

@@ -32,9 +32,9 @@ export const useAppStore = defineStore("app", () => {
}); });
// actions // actions
function toggleSidebar(withoutAnimation: boolean) { function toggleSidebar() {
sidebar.opened = !sidebar.opened; sidebar.opened = !sidebar.opened;
sidebar.withoutAnimation = withoutAnimation; sidebar.withoutAnimation = false;
if (sidebar.opened) { if (sidebar.opened) {
sidebarStatus.value = "opened"; sidebarStatus.value = "opened";
} else { } else {

View File

@@ -1,7 +1,7 @@
<!-- 字典组件示例 --> <!-- 字典组件示例 -->
<script setup lang="ts"> <script setup lang="ts">
const stringValue = ref("1"); // 性别(值为String) const stringValue = ref("1"); // 性别(值为String)
const nmberValue = ref(1); // 性别(值为Number) const numberValue = ref(1); // 性别(值为Number)
</script> </script>
<template> <template>
@@ -22,7 +22,7 @@ const nmberValue = ref(1); // 性别(值为Number)
</el-form-item> </el-form-item>
<el-form-item label="性别"> <el-form-item label="性别">
<dictionary v-model="nmberValue" type-code="gender" /> <dictionary v-model="numberValue" type-code="gender" />
<el-link :underline="false" type="success" class="ml-5" <el-link :underline="false" type="success" class="ml-5"
>值为Number: const value = ref(1); >值为Number: const value = ref(1);
</el-link> </el-link>