组件更新

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

View File

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