组件更新

This commit is contained in:
liqiang
2025-01-30 12:55:58 +08:00
parent 868621a3f1
commit 40b7bd2c94
2 changed files with 67 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
<template>
<div class="user-info-head" @click="editCropper()">
<el-avatar :size="100" :src="options.img" />
<el-avatar :size="100" :src="getBaseURL(options.img)" />
<el-dialog :title="title" v-model="dialogVisiable" width="600px" append-to-body @opened="modalOpened" @close="closeDialog">
<el-row>
<el-col class="flex justify-center">
@@ -50,10 +50,11 @@ import { VueCropper } from 'vue-cropper';
import { useUserInfo } from '/@/stores/userInfo';
import { getCurrentInstance, nextTick, reactive, ref, computed, onMounted, defineExpose } from 'vue';
import { base64ToFile } from '/@/utils/tools';
import headerImage from "/@/assets/img/headerImage.png";
import {getBaseURL} from "/@/utils/baseUrl";
const userStore = useUserInfo();
const { proxy } = getCurrentInstance();
const open = ref(false);
const visible = ref(false);
const title = ref('修改头像');
const emit = defineEmits(['uploadImg']);
@@ -75,7 +76,7 @@ const dialogVisiable = computed({
//图片裁剪数据
const options = reactive({
img: userStore.userInfos.avatar, // 裁剪图片的地址
img: userStore.userInfos.avatar || headerImage, // 裁剪图片的地址
fileName: '',
autoCrop: true, // 是否默认生成截图框
autoCropWidth: 200, // 默认生成截图框宽度
@@ -165,6 +166,7 @@ const updateAvatar = (img) => {
defineExpose({
updateAvatar,
editCropper
});
</script>
@@ -172,7 +174,6 @@ defineExpose({
.user-info-head {
position: relative;
display: inline-block;
height: 120px;
}
.user-info-head:hover:after {

View File

@@ -3,6 +3,7 @@
popper-class="popperClass"
class="tableSelector"
multiple
:collapseTags="props.tableConfig.collapseTags"
@remove-tag="removeTag"
v-model="data"
placeholder="请选择"
@@ -18,20 +19,22 @@
<el-table
ref="tableRef"
:data="tableData"
size="mini"
:size="props.tableConfig.size"
border
row-key="id"
:lazy="props.tableConfig.lazy"
:load="props.tableConfig.load"
:tree-props="props.tableConfig.treeProps"
style="width: 400px"
style="width: 600px"
max-height="200"
height="200"
:highlight-current-row="!props.tableConfig.isMultiple"
@selection-change="handleSelectionChange"
@select="handleSelectionChange"
@selectAll="handleSelectionChange"
@current-change="handleCurrentChange"
>
<el-table-column v-if="props.tableConfig.isMultiple" fixed type="selection" width="55" />
<el-table-column v-if="props.tableConfig.isMultiple" fixed type="selection" reserve-selection width="55" />
<el-table-column fixed type="index" label="#" width="50" />
<el-table-column
:prop="item.prop"
@@ -56,23 +59,31 @@
</template>
<script setup lang="ts">
import { defineProps, reactive, ref, watch } from 'vue';
import {computed, defineProps, onMounted, reactive, ref, watch} from 'vue';
import XEUtils from 'xe-utils';
import { request } from '/@/utils/service';
const props = defineProps({
modelValue: {},
modelValue: {
type: Array || String || Number,
default: () => []
},
tableConfig: {
type: Object,
default:{
url: null,
label: null, //显示值
value: null, //数据值
isTree: false,
lazy: true,
size:'default',
load: () => {},
data: [], //默认数据
isMultiple: false, //是否多选
collapseTags:false,
treeProps: { children: 'children', hasChildren: 'hasChildren' },
columns: [], //每一项对应的列表项
},
},
displayLabel: {},
} as any);
@@ -86,7 +97,7 @@ const multipleSelection = ref();
// 搜索值
const search = ref(undefined);
//表格数据
const tableData = ref();
const tableData = ref([]);
// 分页的配置
const pageConfig = reactive({
page: 1,
@@ -99,7 +110,6 @@ const pageConfig = reactive({
* @param val:Array
*/
const handleSelectionChange = (val: any) => {
multipleSelection.value = val;
const { tableConfig } = props;
const result = val.map((item: any) => {
return item[tableConfig.value];
@@ -117,7 +127,7 @@ const handleSelectionChange = (val: any) => {
const handleCurrentChange = (val: any) => {
const { tableConfig } = props;
if (!tableConfig.isMultiple && val) {
data.value = [val[tableConfig.label]];
// data.value = [val[tableConfig.label]];
emit('update:modelValue', val[tableConfig.value]);
}
};
@@ -150,6 +160,32 @@ const getDict = async () => {
}
};
// 获取节点值
const getNodeValues = () => {
request({
url:props.tableConfig.valueUrl,
method:'post',
data:{ids:props.modelValue}
}).then(res=>{
if(res.data.length>0){
data.value = res.data.map((item:any)=>{
return item[props.tableConfig.label]
})
tableRef.value!.clearSelection()
res.data.forEach((row) => {
tableRef.value!.toggleRowSelection(
row,
true,
false
)
})
}
})
}
/**
* 下拉框展开/关闭
* @param bool
@@ -169,20 +205,12 @@ const handlePageChange = (page: any) => {
getDict();
};
// 监听displayLabel的变化更新数据
watch(
() => {
return props.displayLabel;
},
(value) => {
const { tableConfig } = props;
const result = value
? value.map((item: any) => { return item[tableConfig.label];})
: null;
data.value = result;
},
{ immediate: true }
);
onMounted(()=>{
setTimeout(()=>{
getNodeValues()
},1000)
})
</script>
<style scoped>