Commit a11f3d06 authored by tianhongyang's avatar tianhongyang

企业管理新添账号前端增加验证规则

修复框架自带角色管理模块数据权限取值错误bug
parent 06818197
......@@ -565,6 +565,24 @@ export async function elementMessageSingleton(type = "success", messgage = "") {
}
}
/**
* 检测数组对象中是否有重复数据
* @param {Array} arr
* @param {string | null} mapKey
* @returns
*/
export function hasDuplicates(arr, mapKey = null) {
const map = new Map();
for (const item of arr) {
const key = mapKey ? item[mapKey] : JSON.stringify(item);
if (map.has(key)) {
return { hasRepeat: true, repeatKey: key };
}
map.set(key, true);
}
return { hasRepeat: false, repeatKey: key };
}
// 甲方详情左侧菜单映射
export const detailSideBar = new Map([
// 企业速览
......
......@@ -30,7 +30,7 @@
<!-- 底部提交 取消按钮 -->
<div class="add-account-footer">
<el-button type="primary" size="medium" @click="submitAdd">确定</el-button>
<el-button size="medium" @click="dialogClose">取消</el-button>
<el-button size="medium" @click="dialogStatus = false">取消</el-button>
</div>
</template>
</el-dialog>
......@@ -40,7 +40,7 @@
import { Loading } from 'element-ui';
import { enterpriseAddAccountApi } from "@/api/enterpriseManagement/enterpriseManagement";
import { phoneNumberValidator, requiredStrLengthValidator } from "@/utils/validate";
import { elementMessageSingleton } from "@/utils/";
import { elementMessageSingleton, hasDuplicates } from "@/utils/";
import { v4 } from 'uuid';
export default {
name: "enterpriseAddAccount",
......@@ -111,6 +111,7 @@ export default {
},
addAccount() {
if (this.comAddAccountCount >= 6) return elementMessageSingleton("warning", "该租户下已经添加了五个账号");
if (this.accountForm.accountList?.length >= 5) return elementMessageSingleton("warning", "最多添加五个账号");
const remaining = 6 - this.comAddAccountCount;
const len = this.accountForm?.accountList?.length;
if (len >= remaining) return elementMessageSingleton("warning", `该租户下剩余可添加账号个数为 ${remaining} 个,现已添加 ${len} 个`);
......@@ -123,6 +124,8 @@ export default {
submitAdd() {
this.$refs["accountForm"].validate(async flag => {
if (!flag) return;
const { hasRepeat, repeatKey } = hasDuplicates(JSON.parse(JSON.stringify(this.accountForm.accountList)), "phonenumber");
if (hasRepeat) return elementMessageSingleton("warning", `电话号码 ${repeatKey} 不允许重复创建`);
const loadingService = Loading.service({
target: ".enterprise-add-account-dialog",
lock: true,
......@@ -130,7 +133,6 @@ export default {
});
let successCount = 0;
try {
// 验证通过提交信息
const array = (JSON.parse(JSON.stringify(this.accountForm.accountList))).map(({ nickName, phonenumber }) => ({ nickName, phonenumber }));
let len = array.length;
......@@ -155,7 +157,7 @@ export default {
count++;
}
}
this.dialogClose();
this.dialogStatus = false;
} catch (error) {
console.log(error);
} finally {
......
......@@ -68,7 +68,7 @@
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!-- 添加或修改对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-row>
<el-col :span="12">
......@@ -85,7 +85,7 @@
<el-row>
<el-col :span="12">
<el-form-item label="续约时间" prop="dateRange">
<el-date-picker :disabled="disabled" v-model="form.dateRange" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
<el-date-picker :disabled="disabled" v-model="form.dateRange" style="width: 100%" value-format="yyyy-MM-dd HH:mm:ss"
type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
</el-form-item>
</el-col>
......@@ -98,7 +98,7 @@
<el-row>
<el-col :span="12">
<el-form-item label="企业方案" prop="packageId">
<el-select :disabled="disabled" v-model="form.packageId" placeholder="企业方案" clearable style="width: 240px">
<el-select :disabled="disabled" v-model="form.packageId" placeholder="企业方案" clearable style="width: 100%">
<el-option v-for="dict in packageList" :key="dict.packageId" :label="dict.packageName" :value="dict.packageId" />
</el-select>
</el-form-item>
......@@ -288,8 +288,8 @@ export default {
getList() {
this.loading = true;
getTenantList(this.queryParams).then(response => {
this.tenantList = response.rows;
this.total = response.total;
this.tenantList = response.rows ? response.rows : [];
this.total = response.total ? response.total : 0;
this.loading = false;
}
);
......
......@@ -297,7 +297,7 @@ export default {
/** 根据角色ID查询组织树结构 */
getDeptTree(roleId) {
return deptTreeSelect(roleId).then(response => {
this.deptOptions = response.depts;
this.deptOptions = response.data?.depts ? response.data?.depts : [];
return response;
});
},
......@@ -440,19 +440,19 @@ export default {
}
},
/** 分配数据权限操作 */
handleDataScope(row) {
async handleDataScope(row) {
try {
this.reset();
const deptTreeSelect = this.getDeptTree(row.roleId);
getRole(row.roleId).then(response => {
this.form = response.data;
const res = await this.getDeptTree(row.roleId);
const result = await getRole(row.roleId);
this.form = result.data;
this.openDataScope = true;
this.$nextTick(() => {
deptTreeSelect.then(res => {
this.$refs.dept.setCheckedKeys(res.checkedKeys);
});
});
this.title = "分配数据权限";
});
await this.$nextTick();
this.$refs.dept.setCheckedKeys(res.checkedKeys ? res.checkedKeys : []);
} catch (error) {
console.log(error);
}
},
/** 分配用户操作 */
handleAuthUser: function (row) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment