Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 用户目录增加enabled参数 #149 #218

Merged
merged 4 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions src/pages/src/components/catalog/operation/SetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<h4 class="title">{{$t('密码长度')}}</h4>
<span class="star">*</span>
</div>
<bk-input v-model="defaultPassword.password_min_length.value"
<bk-input v-model="defaultPassword.password_min_length"
type="number"
style="width: 240px;"
:class="{ 'king-input': true, error: passwordLengthError }"
Expand All @@ -45,13 +45,13 @@
<h4 class="title">{{$t('密码必须包含')}}</h4>
<span class="star">*</span>
</div>
<bk-checkbox-group v-model="defaultPassword.password_must_includes.value" style="display: flex;height: 19px;">
<bk-checkbox-group v-model="defaultPassword.password_must_includes" style="display: flex;height: 19px;">
<bk-checkbox value="lower" style="margin-right: 28px;">{{$t('小写字母')}}</bk-checkbox>
<bk-checkbox value="upper" style="margin-right: 28px;">{{$t('大写字母')}}</bk-checkbox>
<bk-checkbox value="int" style="margin-right: 28px;">{{$t('数字')}}</bk-checkbox>
<bk-checkbox value="special" style="margin-right: 28px;">{{$t('特殊字符(除空格)')}}</bk-checkbox>
</bk-checkbox-group>
<p class="error-text" v-if="!defaultPassword.password_must_includes.value.length">{{$t('密码规则不得为空')}}</p>
<p class="error-text" v-if="!defaultPassword.password_must_includes.length">{{$t('密码规则不得为空')}}</p>
</div>

<!-- 密码有效期 -->
Expand All @@ -63,8 +63,8 @@
<div class="bk-button-group">
<bk-button v-for="(item, index) in passwordValidDaysList"
:key="index"
:class="{ 'is-selected': defaultPassword.password_valid_days.value === item.days }"
@click="defaultPassword.password_valid_days.value = item.days">
:class="{ 'is-selected': defaultPassword.password_valid_days === item.days }"
@click="defaultPassword.password_valid_days = item.days">
{{item.text}}
</bk-button>
</div>
Expand All @@ -79,8 +79,8 @@
<div class="bk-button-group">
<bk-button v-for="(item, index) in maxTrailTimesList"
:key="index"
:class="{ 'is-selected': defaultPassword.max_trail_times.value === item.times }"
@click="defaultPassword.max_trail_times.value = item.times">
:class="{ 'is-selected': defaultPassword.max_trail_times === item.times }"
@click="defaultPassword.max_trail_times = item.times">
{{item.text}}
</bk-button>
</div>
Expand All @@ -95,7 +95,7 @@
<span class="icon-user--l" v-bk-tooltips="$t('自动解锁时间提示')"></span>
</div>
</div>
<bk-input v-model="defaultPassword.auto_unlock_seconds.value"
<bk-input v-model="defaultPassword.auto_unlock_seconds"
type="number"
style="width: 240px;"
:class="{ 'king-input': true, error: autoUnlockError }"
Expand Down Expand Up @@ -127,9 +127,9 @@
</div>
<!-- 设置初始密码 -->
<div class="init-password-container"
:class="{ active: defaultPassword.init_password_method.value === 'fixed_preset', error: initPasswordError }"
@click="defaultPassword.init_password_method.value = 'fixed_preset'">
<bk-radio name="radio1" :checked="defaultPassword.init_password_method.value === 'fixed_preset'"
:class="{ active: defaultPassword.init_password_method === 'fixed_preset', error: initPasswordError }"
@click="defaultPassword.init_password_method = 'fixed_preset'">
<bk-radio name="radio1" :checked="defaultPassword.init_password_method === 'fixed_preset'"
class="king-radio">
{{$t('统一初始密码')}}
</bk-radio>
Expand All @@ -139,23 +139,23 @@
autocomplete="new-password"
:type="initPasswordSlash && 'password'"
:placeholder="$t('请输入密码')"
v-model="defaultPassword.init_password.value"
v-model="defaultPassword.init_password"
@input="validateInitPassword"
/>
<i :class="['bk-icon', passwordIconClass]" @click="initPasswordSlash = !initPasswordSlash"></i>
</div>
<p class="error-text" v-show="initPasswordError">{{$t('密码规则校验失败')}}</p>
<!-- 邮箱发送随机密码 -->
<div class="init-email-container"
:class="{ active: defaultPassword.init_password_method.value === 'random_via_mail',
:class="{ active: defaultPassword.init_password_method === 'random_via_mail',
error: initEmailConfigError }">
<div class="email-config-container" @click="defaultPassword.init_password_method.value = 'random_via_mail'">
<div class="email-config-container" @click="defaultPassword.init_password_method = 'random_via_mail'">
<bk-radio class="king-radio" name="radio1"
:checked="defaultPassword.init_password_method.value === 'random_via_mail'">
:checked="defaultPassword.init_password_method === 'random_via_mail'">
{{$t('邮箱发送随机密码')}}
</bk-radio>
<span class="edit-template"
:class="{ disable: defaultPassword.init_password_method.value === 'fixed_preset' }"
:class="{ disable: defaultPassword.init_password_method === 'fixed_preset' }"
@click.stop="toggleEmailTemplate">
{{$t('编辑邮件模板')}}
</span>
Expand All @@ -167,35 +167,35 @@
<h3 class="email-block-name">{{$t('创建账户邮件')}}</h3>
<div class="email-info clearfix">
<p class="title">{{$t('标题')}}<span class="star">*</span></p>
<input type="text" class="input-text" v-model="defaultPassword.init_mail_config.value.title"
<input type="text" class="input-text" v-model="defaultPassword.init_mail_config.title"
@input="validateEmailTemplate" />
</div>
<div class="email-info clearfix">
<p class="title">{{$t('发件人')}}<span class="star">*</span></p>
<input type="text" class="input-text" v-model="defaultPassword.init_mail_config.value.sender"
<input type="text" class="input-text" v-model="defaultPassword.init_mail_config.sender"
@input="validateEmailTemplate" />
</div>
<div class="email-info clearfix">
<p class="title" style="height: 191px">{{$t('正文')}}<span class="star">*</span></p>
<textarea class="textarea-text" v-model="defaultPassword.init_mail_config.value.content"
<textarea class="textarea-text" v-model="defaultPassword.init_mail_config.content"
@input="validateEmailTemplate"></textarea>
</div>
</li>
<li class="email-block">
<h3 class="email-block-name">{{$t('重设密码后的邮件')}}</h3>
<div class="email-info clearfix">
<p class="title">{{$t('标题')}}<span class="star">*</span></p>
<input type="text" class="input-text" v-model="defaultPassword.reset_mail_config.value.title"
<input type="text" class="input-text" v-model="defaultPassword.reset_mail_config.title"
@input="validateEmailTemplate" />
</div>
<div class="email-info clearfix">
<p class="title">{{$t('发件人')}}<span class="star">*</span></p>
<input type="text" class="input-text" v-model="defaultPassword.reset_mail_config.value.sender"
<input type="text" class="input-text" v-model="defaultPassword.reset_mail_config.sender"
@input="validateEmailTemplate" />
</div>
<div class="email-info clearfix">
<p class="title" style="height: 191px">{{$t('正文')}}<span class="star">*</span></p>
<textarea class="textarea-text" v-model="defaultPassword.reset_mail_config.value.content"
<textarea class="textarea-text" v-model="defaultPassword.reset_mail_config.content"
@input="validateEmailTemplate"></textarea>
</div>
</li>
Expand All @@ -206,7 +206,7 @@
</div>

<div class="info-container">
<bk-checkbox v-model="defaultPassword.force_reset_first_login.value">{{$t('首次登录强制修改密码')}}</bk-checkbox>
<bk-checkbox v-model="defaultPassword.force_reset_first_login">{{$t('首次登录强制修改密码')}}</bk-checkbox>
</div>

<!-- 未登录自动冻结 -->
Expand Down Expand Up @@ -329,14 +329,14 @@ export default {
},
// default region
defaultPassword() {
return this.passportInfo ? this.passportInfo.default : null;
return this.passportInfo ? this.passportInfo : null;
},
// 密码输入框右边的眼睛 icon
passwordIconClass() {
return this.initPasswordSlash ? 'icon-eye-slash' : 'icon-eye';
},
isDisabledSubmit() {
return !this.defaultPassword.password_must_includes.value.length
return !this.defaultPassword.password_must_includes.length
|| this.passwordLengthError
|| this.passwordHistoryError
|| this.autoUnlockError
Expand All @@ -359,41 +359,41 @@ export default {
init() {
// 监听密码规则的变化去验证初始密码
this.$watch(() => {
return this.passportInfo.default.password_must_includes.value.length;
return this.passportInfo.password_must_includes.length;
}, () => {
this.validateInitPassword();
});
},
// 校验密码长度
validatePasswordLength() {
this.passwordLengthError = this.defaultPassword.password_min_length.value < 8
|| this.defaultPassword.password_min_length.value > 32;
this.passwordLengthError = this.defaultPassword.password_min_length < 8
|| this.defaultPassword.password_min_length > 32;
},
// 校验密码重复次数
validatePasswordHistory() {
this.passwordHistoryError = this.defaultPassword.max_password_history.value <= 0;
},
// 校验密码解锁时间
validateAutoUnlock() {
this.autoUnlockError = this.defaultPassword.auto_unlock_seconds.value < 30;
this.autoUnlockError = this.defaultPassword.auto_unlock_seconds < 30;
},
// 校验未登录自动冻结天数
validateFreezeDays() {
this.freezeDaysError = this.defaultPassword.freeze_after_days.value <= 0;
},
// 验证初始密码是否符合密码规则
validateInitPassword() {
const password = this.defaultPassword.init_password.value;
const password = this.defaultPassword.init_password;
const passwordRules = {
passwordMinLength: this.defaultPassword.password_min_length.value,
passwordMustIncludes: this.defaultPassword.password_must_includes.value,
passwordMinLength: this.defaultPassword.password_min_length,
passwordMustIncludes: this.defaultPassword.password_must_includes,
};
this.initPasswordError = !this.$validatePassportByRules(password, passwordRules);
},
// 验证邮箱模板
validateEmailTemplate() {
const contentList = [...Object.values(this.defaultPassword.init_mail_config.value),
...Object.values(this.defaultPassword.reset_mail_config.value)];
const contentList = [...Object.values(this.defaultPassword.init_mail_config),
...Object.values(this.defaultPassword.reset_mail_config)];
for (let i = 0; i < contentList.length; i++) {
if (!contentList[i].length) {
this.initEmailConfigError = true;
Expand Down Expand Up @@ -426,7 +426,7 @@ export default {
},
// 展开或隐藏邮件模板
toggleEmailTemplate() {
if (this.defaultPassword.init_password_method.value === 'random_via_mail') {
if (this.defaultPassword.init_password_method === 'random_via_mail') {
this.showEmailTemplate = !this.showEmailTemplate;
}
},
Expand Down
72 changes: 64 additions & 8 deletions src/pages/src/plugins/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ const methods = {
const region = regionArray[0];
Object.entries(regionArray[1]).forEach((regionData) => {
const key = regionData[0];
const value = regionData[1].value;
const enabled = regionData[1].enabled;
arrayData.push({ key, value, region, enabled });
const value = regionData[1];
arrayData.push({ key, value, region });
});
});
return arrayData;
Expand All @@ -82,20 +81,77 @@ const methods = {
try {
const objectData = {};
arr.forEach((regionObject) => {
const { region, key, value, enabled } = regionObject;
const { region, key, value } = regionObject;
if (!objectData[region]) {
objectData[region] = {};
}
objectData[region][key] = {
value,
enabled,
};
objectData[region][key] = value;
});
return objectData;
} catch (e) {
console.warn('参数错误', e);
}
};

Vue.prototype.$convertPassportRes = function (obj) {
const objectData = {};
const enabledKeys = ['max_password_history', 'freeze_after_days'];
obj.forEach((regionArray) => {
try {
if (enabledKeys.includes(regionArray.key)) {
const { key, value, enabled } = regionArray;
this.$set(objectData, key, { value, enabled });
} else {
const { key, value } = regionArray;
this.$set(objectData, key, value);
}
} catch (e) {
console.warn('数据结构异常', e);
}
});
return objectData;
};

Vue.prototype.$convertPassportInfoArray = function (arr) {
try {
const arrayData = [];
Object.entries(arr).forEach((regionArray) => {
const key = regionArray[0];
let value = regionArray[1];
let enabled = true;
if (regionArray[1].value) {
value = regionArray[1].value;
enabled = regionArray[1].enabled;
}
arrayData.push({ key, value, enabled });
});
return arrayData;
} catch (e) {
console.warn('数据结构异常', e);
}
};

Vue.prototype.$convertPassportInfoObject = function (obj) {
try {
const objectData = {};
const enabledKeys = ['max_password_history', 'freeze_after_days'];
Object.entries(obj).forEach((regionArray) => {
Object.entries(regionArray[1]).forEach((regionData) => {
const key = regionData[0];
const value = regionData[1];
if (enabledKeys.includes(key)) {
const enabled = true;
this.$set(objectData, key, { value, enabled });
yuri0528 marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.$set(objectData, key, value);
}
});
});
return objectData;
} catch (e) {
console.warn('数据结构异常', e);
}
};
// 获取字符串长度,中文为 2 个字符长度
Vue.prototype.$getStringLength = function (string) {
// 匹配所有的中文
Expand Down
4 changes: 2 additions & 2 deletions src/pages/src/views/catalog/operation/LocalAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default {
};
},
created() {
this.passportInfo = JSON.parse(JSON.stringify(this.$store.state.catalog.defaults.password));
this.passportInfo = this.$convertPassportInfoObject(this.$store.state.catalog.defaults.password);
},
methods: {
// 上一步
Expand Down Expand Up @@ -120,7 +120,7 @@ export default {
this.isLoading = true;
await this.$store.dispatch('catalog/ajaxPostPassport', {
id: this.catalogId,
data: this.$convertObjectToArray(this.passportInfo),
data: this.$convertPassportInfoArray(this.passportInfo),
});
this.$bus.$emit('updateCatalogList');
this.messageSuccess(this.$t('保存成功'));
Expand Down
4 changes: 2 additions & 2 deletions src/pages/src/views/catalog/operation/LocalSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
this.passwordHasCreated = false;
this.current = 2;
} else {
this.passwordInfo = this.$convertArrayToObject(passportRes.data);
this.passwordInfo = this.$convertPassportRes(passportRes.data);
}
} catch (e) {
console.warn(e);
Expand Down Expand Up @@ -130,7 +130,7 @@ export default {
const action = this.passwordHasCreated ? 'catalog/ajaxPutPassport' : 'catalog/ajaxPostPassport';
await this.$store.dispatch(action, {
id: this.catalogInfo.id,
data: this.$convertObjectToArray(this.passwordInfo),
data: this.$convertPassportInfoArray(this.passwordInfo),
});
this.handleSaveSuccess();
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/src/views/organization/details/UserMaterial.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ export default {
const currentPasswordInfo = this.$store.state.organization.currentPasswordInfo;
if (currentPasswordInfo.id === this.currentCategoryId && currentPasswordInfo.data) {
this.passwordRules = {
passwordMinLength: currentPasswordInfo.data.password_min_length.value,
passwordMustIncludes: currentPasswordInfo.data.password_must_includes.value,
passwordMinLength: currentPasswordInfo.data.password_min_length,
passwordMustIncludes: currentPasswordInfo.data.password_must_includes,
};
} else {
try {
Expand All @@ -340,8 +340,8 @@ export default {
});
const passwordInfo = this.$convertArrayToObject(res.data).default;
this.passwordRules = {
passwordMinLength: passwordInfo.password_min_length.value,
passwordMustIncludes: passwordInfo.password_must_includes.value,
passwordMinLength: passwordInfo.password_min_length,
passwordMustIncludes: passwordInfo.password_must_includes,
};
this.$store.commit('organization/updatePasswordInfo', {
id: this.currentCategoryId,
Expand Down