feat:人员角色搜索

This commit is contained in:
dzc committed 2025-04-15 16:58:09 +08:00
1 parent e41471cb7d
commit b437f94d1a
3 files changed
+103

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
<template>
<el-select
style="width: 100%"
v-model="state.selectId"
:placeholder="props.placeholder"
clearable
remote-show-suffix
filterable
remote
:disabled="props.disabled"
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
>
<el-option v-for="v in state.options" :key="v.roleId" :label="`${v.roleName}`" :value="v.roleId">
<div class="flex items-center">
<div class="color-primary">{{ v.roleName }}</div>
</div>
</el-option>
</el-select>
</template>
<script setup lang="ts" name="select-role">
import { reactive } from "vue"
import * as roleApi from "/@/api/admin/role"
const selectId = defineModel()
const props = withDefaults(
defineProps<{
placeholder?: string
apiParams?: any
autoFirst?: boolean
disabled?: boolean
}>(),
{
placeholder: "请选择",
apiParams: {},
autoFirst: false,
disabled: false,
},
)
const queryForm = reactive<any>({
roleName: null,
current: 1,
size: 10,
})
const state = reactive<any>({
loading: true,
selectId: selectId,
options: [],
})
watch(
selectId,
(newVal, oldValue) => {
if (newVal == oldValue) return
state.selectId = newVal
getOptions()
},
{ immediate: true },
)
async function getOptions() {
try {
state.loading = true
const _pa = {
...queryForm,
...props.apiParams,
}
const { data } = await roleApi.pageList(_pa)
state.options = data.records ?? []
if (props.autoFirst && state.options.length != 0) {
state.selectId = state.options[0].id
}
} finally {
setTimeout(() => (state.loading = false), 500)
}
}
function remoteSearch(params: string) {
if (params != queryForm.roleName) {
queryForm.roleName = params
getOptions()
}
}
function clear() {
state.selectId = null
getOptions()
}
onMounted(() => {
props.autoFirst && getOptions()
})
</script>
+2
View File
@@ -30,6 +30,7 @@ import SelectHardSpuCategory from "/@/components/Select/SelectHardSpuCategory.vu
import SelectHard from "/@/components/Select/SelectHard.vue"
import SelectHardSpu from "/@/components/Select/SelectHardSpu.vue"
import SelectHardGroup from "/@/components/Select/selectHardGroup.vue"
import SelectRole from "/@/components/Select/SelectRole.vue"
// 第三方组件
import ElementPlus from "element-plus"
@@ -81,6 +82,7 @@ export default {
app.component("SelectHandlerUser", SelectHandlerUser)
app.component("SelectSupplier", SelectSupplier)
app.component("SelectMchRule", SelectMchRule)
app.component("SelectRole", SelectRole)
// 导入全部的elmenet-plus的图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
+3
View File
@@ -26,6 +26,9 @@
<el-form-item style="width: 250px" label="部门" prop="deptId">
<select-dept v-model="state.queryForm.deptId" clearable />
</el-form-item>
<el-form-item style="width: 250px" label="角色" prop="role">
<select-role v-model="state.queryForm.role" clearable />
</el-form-item>
<el-form-item>
<el-button icon="Search" type="primary" @click="getDataList">查询</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>