diff --git a/projects/WebMVC/wwwroot/router/admin/command/edit.html b/projects/WebMVC/wwwroot/router/admin/command/edit.html index 4b13a466..050c60e8 100644 --- a/projects/WebMVC/wwwroot/router/admin/command/edit.html +++ b/projects/WebMVC/wwwroot/router/admin/command/edit.html @@ -100,17 +100,16 @@ {{deviceName}} - + {{param.description}}: - + - + {{getPropertyErrors2(index)}} + - @@ -147,7 +146,8 @@ schema: null, model: null, data: null - } + }, + errors: [] } }, computed: { @@ -212,6 +212,53 @@ change: function (name) { return this.$validProperty(name); }, + updateErrorMessages2: function (messages, message, valid) { + if (valid()) { + if (Enumerable.from(messages).any(o => o === message)) { + var index = _.findIndex(messages, o => o === message); + messages.splice(index, 1); + } + } + else { + if (!Enumerable.from(messages).any(o => o === message)) { + messages.push(message); + } + } + }, + change2: function (index) { + var item = this.data.model.parameters[index]; + var value = item.value; + if (item.type === 'integer') { + value = parseInt(value); + } + else if (item.type === 'float') { + value = parseFloat(value); + } + var messages = this.errors[index]; + if (!messages) { + messages = this.errors[index] = []; + } + if (item.required) { + var message = "必须填写" + item.description; + this.updateErrorMessages2(messages, '必填项', o => !(o === 0 || o)); + } + if (item.minimum) { + var minimum = parseFloat(item.minimum); + var message = "必须大于" + item.minimum; + this.updateErrorMessages2(messages, message, o => value > minimum); + } + if (item.maxinum) { + var maxinum = parseFloat(item.maxinum); + var message = "必须小于" + item.maxinum; + this.updateErrorMessages2(messages, message, o => value < maxinum); + } + }, + hasErrors2: function (index) { + return this.errors[index] && this.errors[index].length; + }, + getPropertyErrors2: function (index) { + return this.errors[index]; + }, hasPermission: function () { var permission = this.mode + '-' + this.entity; return Enumerable.from(store.state.permissions).any(o => o.toLowerCase() === permission.toLowerCase()); @@ -277,6 +324,7 @@ 'data.model.apiId': function (val) { var vm = this; if (val && this.data.model.deviceId) { + vm.errors = []; var url = this.path + 'Api?apiId=' + val + '&deviceId=' + this.data.model.deviceId; axios.get(url).then(function (response) { console.log(response.data);