From 4ab8ff449fd0ae87de58a64509f1218eaf0a1efd Mon Sep 17 00:00:00 2001 From: wkl505997900 <505997900@qq.com> Date: Mon, 24 Apr 2023 16:11:22 +0800 Subject: [PATCH] Verify the host name field before and after adding a host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ant-design-pro/layouts/UserLayout.vue | 3 +- src/views/assests/HostEdition.vue | 80 ++++++++++--------- src/views/assests/HostManagement.vue | 24 +++--- src/views/assests/components/EditableCell.vue | 48 ++++++++--- src/views/assests/components/addMoreHost.vue | 54 ++++++++++--- src/views/leaks/components/UploadFile.vue | 4 +- src/views/user/Login.vue | 2 +- src/views/user/Register.vue | 6 +- 8 files changed, 145 insertions(+), 76 deletions(-) diff --git a/src/vendor/ant-design-pro/layouts/UserLayout.vue b/src/vendor/ant-design-pro/layouts/UserLayout.vue index 72dc176..b054097 100644 --- a/src/vendor/ant-design-pro/layouts/UserLayout.vue +++ b/src/vendor/ant-design-pro/layouts/UserLayout.vue @@ -158,7 +158,8 @@ export default { } .footer { - width: 100%; + position: absolute; + width: 98%; bottom: 0; padding: 0 16px; margin: 155px 0 24px; diff --git a/src/views/assests/HostEdition.vue b/src/views/assests/HostEdition.vue index fac76fc..a945a68 100644 --- a/src/views/assests/HostEdition.vue +++ b/src/views/assests/HostEdition.vue @@ -12,10 +12,10 @@ :maxLength="50" v-decorator="[ 'host_name', - {rules: [{ required: true, message: '请输入主机名称'}, {validator: checkNameInput}]} + {rules: [{ required: true, message: '请输入主机名称'}, {validator: checkNameInput, validateTrigger: 'blur'}]}, ]" placeholder="请输入主机名称,50个字符以内"> - + @@ -64,6 +64,7 @@ + :placeholder="pageType === 'create' ? '请设置主机登录密码' : '请输入主机登陆密码, 若未修改主机用户名或端口可以为空'"> - - 取消 state.host.hostInfo }) @@ -200,6 +193,16 @@ export default { } }, methods: { + handleUserChange(value) { + if (this.pageType === 'edit') { + value.target.value === this.basicHostInfo.ssh_user ? this.UserRequired = false : this.UserRequired = true + } + }, + handlePortChange(value) { + if (this.pageType === 'edit') { + value === this.basicHostInfo.ssh_port ? this.PortRequired = false : this.PortRequired = true + } + }, // 获取主机组列表数据 getHostGroupList() { const _this = this; @@ -240,18 +243,23 @@ export default { } } } - editHost(tableParams, this.hostId) - .then(function (res) { - _this.$message.success(res.message); - store.dispatch('resetHostInfo'); - router.push('/assests/hosts-management'); - }) - .catch(function (err) { - _this.$message.error(err.response.message); - }) - .finally(function () { - _this.submitLoading = false; - }); + if (JSON.stringify(tableParams) === '{}') { + this.$message.info('未存在修改数据!') + this.submitLoading = false; + } else { + editHost(tableParams, this.hostId) + .then(function (res) { + _this.$message.success(res.message); + store.dispatch('resetHostInfo'); + router.push('/assests/hosts-management'); + }) + .catch(function (err) { + _this.$message.error(err.response.message); + }) + .finally(function () { + _this.submitLoading = false; + }); + } } else { addHost(values) .then(function (res) { @@ -278,15 +286,15 @@ export default { router.go(-1); }, checkNameInput(rule, value, cb) { - if (/[^0-9a-z_.]/.test(value)) { + if (!/^\S.*\S$/.test(value)) { /* eslint-disable */ - cb('只能输入数字、小写字母和英文.和_'); + cb('首尾不允许空格'); /* eslint-enable */ return; } - if (/[_]$/.test(value)) { + if (!/^(?!\s*$).+/.test(value)) { /* eslint-disable */ - cb('结尾不能是英文下划线'); + cb('不允许全空格'); /* eslint-enable */ return; } diff --git a/src/views/assests/HostManagement.vue b/src/views/assests/HostManagement.vue index 81c25eb..080c145 100644 --- a/src/views/assests/HostManagement.vue +++ b/src/views/assests/HostManagement.vue @@ -58,7 +58,7 @@ slot="hostName" slot-scope="hostName, record">{{ hostName }} {{ isMana ? '是' : '否' }} - {{ statusMap(status) }} + {{ hostStatusMap[status] }} {{ scene ? ( scene === 'normal' ? '通用' : scene ) : '暂无' }} + +
- ****** + {{ countStar(form[formkey]) }} {{ value || ' ' }}
@@ -58,15 +60,15 @@ export default { } }; const checkNameInput = (rule, value, callback) => { - if (/[^0-9a-z_.]/.test(value)) { + if (!/^\S.*\S$/.test(value)) { /* eslint-disable */ - callback(new Error('只能输入数字、小写字母和英文.和_')); + callback(new Error('首尾不允许空格')); /* eslint-enable */ return; } - if (/[_]$/.test(value)) { + if (!/^(?!\s*$).+/.test(value)) { /* eslint-disable */ - callback(new Error('结尾不能是英文下划线')); + callback(new Error('不允许全空格')); /* eslint-enable */ return; } @@ -102,6 +104,13 @@ export default { }; }, methods: { + countStar(num) { + let str = '' + for (let i = 0; i < num.length; i++) { + str += '*' + } + return str + }, handleChange(e) { const value = e.target.value; this.value = value; @@ -113,22 +122,39 @@ export default { check() { this.$refs.ruleForm.validate(valid => { if (valid) { - this.editable = false; - this.$emit('change', this.value); + if (this.editable) { + // 判断当前状态,只对处于修改状态的组件执行此操作,节省性能 + this.editable = false; + this.$emit('allowSub') + this.$emit('change', this.value); + } } else { return false; } }); }, edit() { + this.$emit('unSubmit') this.editable = true; + }, + handleClickOutside(event) { + // 鼠标监听事件 + const target = event.target + const wrapper = this.$refs.childitem + // 判断点击的区域是否是当前组件的区域 + if (!wrapper.contains(target)) { + // 当点击组件之外时 执行校验操作 + this.check() + } } }, created() { }, + beforeDestroy() { + document.removeEventListener('mouseup', this.handleClickOutside) + }, mounted() { - // this.edit() - // this.check() + document.addEventListener('mouseup', this.handleClickOutside) }, computed: { form () { diff --git a/src/views/assests/components/addMoreHost.vue b/src/views/assests/components/addMoreHost.vue index 830bf03..4cd9a65 100644 --- a/src/views/assests/components/addMoreHost.vue +++ b/src/views/assests/components/addMoreHost.vue @@ -32,7 +32,8 @@ ref="host_ip" formkey="host_ip" :text="String(text)" - @uploadstatus="uploadstatus($event)" + @unSubmit="unSubmit()" + @allowSub="allowSub()" @change="onCellChange(record.key, 'host_ip', $event)" />