wujingjing
2024-10-21 6dc8a04ea58dbcf253104504f1507997cc866ee6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
    <ywDialog
        v-model="dialogIsShow"
        :showHeaderIcon="false"
        :title="dialogTitle"
        width="470"
        :showFooter="false"
        @dlgClosed="closeDialog"
        :closeOnClickModal="true"
    >
        <el-form :model="item" ref="dialogFormRef" :rules="dialogFormRules" :label-width="labelWidth">
            <el-form-item :label="colList[key]?.label" :prop="key" v-for="key in Object.keys(colList)">
                <el-input readonly :modelValue="item[key]"></el-input>
            </el-form-item>
        </el-form>
    </ywDialog>
</template>
 
<script setup lang="ts">
import ywDialog from '/@/components/dialog/yw-dialog.vue';
 
import type { FormInstance, FormRules } from 'element-plus';
 
import { computed, onMounted, ref } from 'vue';
import { getTextWidth } from '/@/utils/util';
 
const props = defineProps(['item', 'colList','title']);
//#region ====================== 增加、修改记录操作, dialog init======================
const dialogTitle = computed(() => {
    return props.title ?? `记录详情`;
});
 
const dialogIsShow = defineModel({
    type: Boolean,
});
const dialogFormRef = ref<FormInstance>(null);
 
const dialogFormRules = ref<FormRules>({
    // title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
    // prompt: [{ required: true, message: '请输入提示词', trigger: 'blur' }],
});
 
//#endregion
 
const closeDialog = () => {
    dialogIsShow.value = false;
};
 
const measureWidthOffset = 12;
const labelWidth = ref(undefined);
const getMaxLabelWidth = () =>{
 
    let maxLen = 0;
    let maxStr = '';
    Object.values(props.colList ).map(item=>{
        const label = (item as any).label as string;
 
        const currentLen = label.gblen();
        if(currentLen> maxLen){
            maxLen = currentLen
            maxStr = label;
        }
    })
 
 
    const maxWidth = getTextWidth(maxStr,{
        size: '14px',
    })+measureWidthOffset;
    labelWidth.value = maxWidth;
}
 
onMounted(() => {
    getMaxLabelWidth();
});
</script>
<style scoped lang="scss"></style>