feat : 对接人用户替换

This commit is contained in:
2024-08-05 01:01:35 +08:00
parent 66bd341692
commit ee869f3c34
2 changed files with 82 additions and 25 deletions

View File

@@ -21,6 +21,12 @@ export const getUserAccount = () => {
method: 'get' method: 'get'
}) })
} }
export const judgeIsSameRole = () => {
return request({
url: '/admin/mosr/user/company/same',
method: 'get'
})
}
// 查询角色信息 // 查询角色信息
export const getRolesOpt = () => { export const getRolesOpt = () => {

View File

@@ -4,28 +4,33 @@
<fvForm :schema="schame" @getInstance="getInstance" :rules="rules"></fvForm> <fvForm :schema="schame" @getInstance="getInstance" :rules="rules"></fvForm>
<div class="oper-page-btn"> <div class="oper-page-btn">
<el-button color="#DED0B2" @click="handleSubmit">提交</el-button> <el-button color="#DED0B2" @click="handleSubmit">提交</el-button>
<el-button @click="handleBack">返回</el-button> <el-button @click="handleBack">返回</el-button>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="jsx"> <script setup lang="jsx">
import { operate } from '@/api/user/user.js' import {ElLoading, ElMessageBox, ElNotification} from 'element-plus';
import { ElLoading, ElNotification } from 'element-plus'; import {useTagsView} from '@/stores/tagsview.js'
import { useTagsView } from '@/stores/tagsview.js' import {useAuthStore} from '@/stores/userstore.js'
import { useAuthStore } from '@/stores/userstore.js' import {useCacheStore} from "@/stores/cache.js";
import { useCacheStore } from "@/stores/cache.js"; import {
import { getDeptOpt, getSubCompOpt, getRolesOpt, getJobOpt, getUserDetail } from '@/api/user/user.js' getDeptOpt,
import { onBeforeMount } from 'vue'; getSubCompOpt,
getRolesOpt,
getJobOpt,
getUserDetail,
operate,
judgeIsSameRole
} from '@/api/user/user.js'
const tagsViewStore = useTagsView() const tagsViewStore = useTagsView()
const authStore = useAuthStore() const authStore = useAuthStore()
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const route = useRoute() const route = useRoute()
const form = ref(null) const form = ref(null)
const currentRoleArray = ref([])
const loading = ref(false) const loading = ref(false)
const localData = reactive({ const localData = reactive({
subCompanyIdOpt: [], subCompanyIdOpt: [],
departmentIdOpt: [], departmentIdOpt: [],
@@ -33,7 +38,7 @@ const localData = reactive({
jobOpt: [] jobOpt: []
}) })
const schame = computed(()=>{ const schame = computed(() => {
let arr = [ let arr = [
{ {
label: '公司', label: '公司',
@@ -49,7 +54,7 @@ const schame = computed(()=>{
}, },
on: { on: {
change: async (val) => { change: async (val) => {
const { data } = await getDeptOpt({subCompanyId: val}) const {data} = await getDeptOpt({subCompanyId: val})
localData.departmentIdOpt = data localData.departmentIdOpt = data
} }
} }
@@ -114,6 +119,49 @@ const schame = computed(()=>{
placeholder: '请选择', placeholder: '请选择',
multiple: true, multiple: true,
data: localData.roleOpt data: localData.roleOpt
},
on: {
change: async (val) => {
const {code, data} = await judgeIsSameRole()
if (code === 1000) {
console.log('currentRoleArray.value', currentRoleArray.value)
if (currentRoleArray.value.length !== 0) {
val.forEach(selectItem => {
currentRoleArray.value.forEach(currentItem => {
if (data[selectItem]?.length > 0 && selectItem != currentItem) {
ElMessageBox.confirm(`此角色存在对应人员:${data[selectItem][0].nickName},您确定要替换该人员?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
}).catch((action) => {
if (action == 'cancel') {
form.value.getValues().roleIds = form.value.getValues().roleIds.filter(roleItem => roleItem != selectItem);
}
})
}
})
})
} else {
val.forEach(selectItem => {
if (data[selectItem]?.length > 0) {
ElMessageBox.confirm(`此角色存在对应人员:${data[selectItem][0].nickName},您确定要替换该人员?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
}).catch((action) => {
if (action == 'cancel') {
form.value.getValues().roleIds = form.value.getValues().roleIds.filter(roleItem => roleItem != selectItem);
}
})
}
})
}
}
}
} }
}, },
{ {
@@ -156,9 +204,9 @@ const schame = computed(()=>{
}, },
] ]
let editArr = [] let editArr = []
if(!route.query.isAdd) { if (!route.query.isAdd) {
arr.forEach(item=>{ arr.forEach(item => {
if(item.prop != 'password') { if (item.prop != 'password') {
editArr.push(item) editArr.push(item)
} }
}) })
@@ -198,25 +246,26 @@ const init = async () => {
} }
const getInfo = async () => { const getInfo = async () => {
if(!route.query.id) return if (!route.query.id) return
// 获取详情数据 // 获取详情数据
const { data } = await getUserDetail(route.query.id) const {data} = await getUserDetail(route.query.id)
if(data.subCompanyId) { if (data.subCompanyId) {
const res = await getDeptOpt({subCompanyId: data.subCompanyId}) const res = await getDeptOpt({subCompanyId: data.subCompanyId})
localData.departmentIdOpt = res.data localData.departmentIdOpt = res.data
} }
nextTick(()=>{ nextTick(() => {
form.value.setValues(data) form.value.setValues(data)
currentRoleArray.value = form.value.getValues().roleIds
}) })
} }
const handleSubmit = async () => { const handleSubmit = async () => {
const loading = ElLoading.service({fullscreen: true}) const loading = ElLoading.service({fullscreen: true})
const { isValidate } = await form.value.validate() const {isValidate} = await form.value.validate()
if(!isValidate) return Promise.reject() if (!isValidate) return Promise.reject()
const values = form.value.getValues() const values = form.value.getValues()
operate(values, route.query.userType).then(res=>{ operate(values, route.query.userType).then(res => {
ElNotification({ ElNotification({
title: route.query.isAdd ? '新增' : '编辑', title: route.query.isAdd ? '新增' : '编辑',
message: res.msg, message: res.msg,
@@ -224,7 +273,9 @@ const handleSubmit = async () => {
}) })
loading.close() loading.close()
res.code === 1000 ? tagsViewStore.delViewAndGoView('/system/user') : null res.code === 1000 ? tagsViewStore.delViewAndGoView('/system/user') : null
}).finally(()=>{ }).catch(() => {
loading.close()
}).finally(() => {
loading.close() loading.close()
}) })
} }
@@ -233,10 +284,10 @@ const handleBack = () => {
history.back() history.back()
} }
onMounted(async ()=>{ onMounted(async () => {
loading.value = true loading.value = true
await init() await init()
if(!route.query.isAdd) { if (!route.query.isAdd) {
await getInfo() await getInfo()
} }
loading.value = false loading.value = false