3 changed files with 175 additions and 4 deletions
@ -0,0 +1,152 @@ |
|||
<script lang='ts' setup> |
|||
import { computed, onMounted, nextTick } from 'vue' |
|||
import { criteriaForPeopleList } from '@/api/hr/org/type' |
|||
import request from '@/utils/request'; |
|||
import { useAttrs } from 'vue' |
|||
const attrs = useAttrs() |
|||
const props = withDefaults( |
|||
defineProps<{ |
|||
modelValue?: string |
|||
disabled?: boolean |
|||
}>(), |
|||
{} |
|||
) |
|||
interface User { |
|||
id: number |
|||
name: string |
|||
number: string |
|||
key: string |
|||
icon: string |
|||
department: string |
|||
role: string |
|||
} |
|||
const emits = defineEmits<{ |
|||
(e: 'update:modelValue', value: string): void |
|||
}>() |
|||
const userDialogEl = ref() |
|||
// const value:any = computed({ |
|||
// get() { |
|||
// return props.modelValue |
|||
// }, |
|||
// set(newVal: string) { |
|||
// emits('update:modelValue', newVal) |
|||
// } |
|||
// }) |
|||
// const userlist = ref<any>("") |
|||
const value = ref([]) |
|||
|
|||
|
|||
watch(value,(newValue)=>{ |
|||
if(newValue.length > 0){ |
|||
let str = "" |
|||
|
|||
let userAry = new Array |
|||
|
|||
newValue.forEach(item =>{ |
|||
console.log(item) |
|||
userAry.push(item) |
|||
|
|||
}) |
|||
str = userAry.join(',') |
|||
console.log(str) |
|||
emits('update:modelValue', str) |
|||
// userlist.value = userAry.join(',') |
|||
// |
|||
}else{ |
|||
let str = "" |
|||
console.log(str) |
|||
emits('update:modelValue', str) |
|||
} |
|||
},{ deep: true }) |
|||
|
|||
const openDialog = () => { |
|||
// console.log("value-----》",value.value) |
|||
userDialogEl.value.open() |
|||
} |
|||
|
|||
function parseStringToArray(str:string) { |
|||
try { |
|||
// 尝试解析JSON格式字符串 |
|||
const result = JSON.parse(str); |
|||
// 验证解析结果是否为数组 |
|||
if (Array.isArray(result)) { |
|||
return result; |
|||
} else { |
|||
//console.error("解析结果不是数组"); |
|||
return []; |
|||
} |
|||
} catch (error) { |
|||
//console.error("字符串格式错误,无法解析为数组:", error.message); |
|||
return []; |
|||
} |
|||
} |
|||
onMounted(() => { |
|||
getManConts() |
|||
setTimeout(()=>{ |
|||
value.value = parseStringToArray(props.modelValue) |
|||
},500 ) |
|||
}) |
|||
const url = "/javasys/lowCode/manCont/getManContsByKeys" |
|||
//console.log(attrs.value) |
|||
const keys = computed(()=>{ |
|||
if(attrs.queryBy == 'role'){ |
|||
return attrs.roleRange |
|||
}else{ |
|||
return attrs.orgRange |
|||
} |
|||
}) |
|||
function getManContsByKeys() { |
|||
//console.log(11111) |
|||
|
|||
return request({ |
|||
url: url, |
|||
method: "post", |
|||
data: { |
|||
keys: keys.value, |
|||
}, |
|||
}); |
|||
|
|||
} |
|||
const options = ref([]) |
|||
|
|||
function getManConts(){ |
|||
getManContsByKeys().then(({data})=>{ |
|||
data.forEach((element: any) => { |
|||
element.icon = element.name+"("+element.number+")" |
|||
element.deparment = "["+element.deparment+"] - "+element.icon |
|||
}); |
|||
options.value = data |
|||
//console.log(options.value) |
|||
|
|||
}) |
|||
} |
|||
|
|||
|
|||
</script> |
|||
<template> |
|||
|
|||
<!-- <el-input placeholder="请选择用户" v-bind="$props" v-model="value" @click="openDialog" clearable> |
|||
<template #append> |
|||
<i class="icon-user" @click.stop="openDialog"></i> |
|||
</template> |
|||
</el-input> |
|||
<user-dialog ref="userDialogEl" v-model="value" /> --> |
|||
<el-select-v2 |
|||
placeholder="请选择用户" |
|||
v-model="value" |
|||
node-key="key" |
|||
:props="{ label: 'deparment', value: 'icon' }" |
|||
:options="options" |
|||
filterable |
|||
:render-after-expand="false" |
|||
|
|||
|
|||
multiple |
|||
clearable |
|||
collapse-tags |
|||
collapse-tags-tooltip |
|||
:max-collapse-tags="4" |
|||
/> |
|||
|
|||
</template> |
|||
<style lang='scss' scoped></style> |
|||
Loading…
Reference in new issue