优化组件

This commit is contained in:
吕金泽 2022-08-05 19:13:27 +08:00
parent 64ef2b6022
commit 20e29bbb07
4 changed files with 42 additions and 26 deletions

View File

@ -19,8 +19,8 @@
<el-switch
v-if="col.if === undefined ? true : col.if(scope.row)"
v-model="scope.row[col.field]"
:active-value="col.activeValue || 1"
:inactive-value="col.inactiveValue || 0"
:active-value="(col.activeValue || 1) + ''"
:inactive-value="(col.inactiveValue || 0) + ''"
@change="col.change(scope.row)"
/>
</div>
@ -40,6 +40,7 @@
<a v-else-if="col.type == 'downloadAll'" @click="$common.downloadMore(scope.row[col.field])" href="javascript:;">下载</a>
<el-image
v-else-if="col.type === 'image'"
preview-teleported
:src="scope.row[col.field] && scope.row[col.field].startsWith('http') ? scope.row[col.field] : $global.baseApi + scope.row[col.field]"
:preview-src-list="[scope.row[col.field] && scope.row[col.field].startsWith('http') ? scope.row[col.field] : $global.baseApi + scope.row[col.field]]"
/>

View File

@ -108,7 +108,7 @@ function setValue(value){
if(props.multiple && props.join){
selectValue.value = value ? value.split(',') : []
}else{
selectValue.value = value ? value.toString() : ''
selectValue.value = value || value === 0 ? value.toString() : ''
}
}

View File

@ -1,31 +1,37 @@
<template>
<el-switch
v-model="selectValue"
:active-value="activeValue"
:inactive-value="inactiveValue"
v-bind="props.props"
v-model="selectValue"
:active-value="activeValue + ''"
:inactive-value="inactiveValue + ''"
v-bind="props.props"
/>
</template>
<script setup>
import {ref, watch} from 'vue'
const emit = defineEmits(['update:modelValue'])
const selectValue = ref(false)
const props = defineProps({
modelValue: {
type: Boolean,
default: false
},
activeValue: Boolean | String | Number,
inactiveValue: Boolean | String | Number,
props: Object
})
const emit = defineEmits(['update:modelValue'])
const selectValue = ref('')
const props = defineProps({
modelValue: Boolean | String | Number,
activeValue: Boolean | String | Number,
inactiveValue: Boolean | String | Number,
props: Object
})
selectValue.value = props.modelValue
watch(() => props.modelValue, (value) => {
dynamicSetValue(props.modelValue)
watch(() => props.modelValue, (value) => {
dynamicSetValue(value)
})
function dynamicSetValue(value){
if(typeof(value) == 'boolean'){
selectValue.value = value
})
watch(selectValue, (value) => {
emit('update:modelValue', value)
})
}else{
if(value || value == 0){
selectValue.value = value + ''
}
}
}
watch(selectValue, (value) => {
emit('update:modelValue', value)
})
</script>

View File

@ -43,9 +43,12 @@
:show-file-list="false"
:multiple="multiple"
:limit="limit"
:on-success="handleAvatarSuccess"
:on-success="onSuccess"
:on-error="onError"
:before-upload="beforeUpload"
:on-exceed="onExceed"
:file-list="fileList"
:disabled="isUploading"
>
<el-icon class="uploadIcon">
<ElIconPlus />
@ -238,7 +241,13 @@ export default {
handleDownload(file) {
console.log(file)
},
handleAvatarSuccess(res, file, fileList) {
beforeUpload(){
this.isUploading = true
},
onError(){
this.isUploading = true
},
onSuccess(res, file, fileList) {
console.log(res)
this.fileList = fileList
if (res.data) {