You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/WebMVC/wwwroot/router/shared/edit.html

113 lines
5.2 KiB

<template>
<layout v-bind:title="data.schema.title">
<h1>{{data.schema.title}}<span v-if="mode==='Edit'">编辑页</span><span v-else>新建页</span></h1>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body" v-if="hasPermission('Edit')">
<form ref="form" class="form-horizontal query" v-if="hasPermission('Read')" :action="url" @submit.prevent="onSubmit">
<input type="hidden" name="id" :value="data.model.id" />
<div class="form-group row" v-for="(value,key,index) in data.schema.properties" v-if="show(key,value)">
<label class="col-sm-2 col-form-label" :for="key">{{value.title}}:</label>
<div class="col-sm-6 form-control" style="border-color:transparent;height:auto;min-height:calc(2.25rem + 2px);" :title="key">
<template v-if="value.readOnly&&mode!=='Add'">
<input type="hidden" :name="key" :value="data.model[key]" />
<component :is="getDisplayComponent(key)" :title="value.title" :name="key" :value="data.model[key]" :data="data.data" v-if="data.model" />
</template>
<template v-else>
<component :is="getEditComponent(key)" :title="value.title" :name="key" :value="data.model[key]" :data="data.data" :valid="valid(value,key,data.model[key])" :mode="'edit'" v-if="data.model" />
</template>
</div>
<div class="col-sm-4">{{value.description}}</div>
</div>
</form>
</div>
<div class="card-footer">
<div class="row">
<div class="col-sm-2">
</div>
<div class="col-sm-10">
<a href="javascript:;" class="btn btn-primary" v-if="hasPermission('Edit')" v-on:click="onSubmit()">确定</a>
<router-link :to="{path:'/router/shared/list.html',query:{entity:entity}}" class="btn btn-default" v-if="hasPermission('Read')">返回</router-link>
</div>
</div>
</div>
</div>
</div>
</div>
</layout>
</template>
<script>
export default {
name: 'page-edit',
data: function () {
return {
mode: this.$route.query.mode,
entity: this.$route.query.entity,
data: {
schema: {
title: ''
},
model: {},
data: {}
}
}
},
computed: {
url: function () {
return '/IoTCenter/Admin/' +
this.$route.query.entity + '/' +
this.$route.query.mode +
(this.mode === 'Edit' ? ('?id=' + this.$route.query.id) : '');
}
},
mounted: function () {
this.load();
},
methods: {
load: function () {
var vm = this;
var url = this.baseUrl + this.url;
axios.get(url).then(function (response) {
vm.data = response.data;
vm.$nextTick(function () {
$(vm.$refs.form).removeData('validator');
$(vm.$refs.form).removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(vm.$refs.form);
});
});
},
hasPermission: function (cmd) {
var permission = cmd + '-' + this.entity;
return Enumerable.from(store.state.permissions).any(o => o === permission);
},
getEditComponent: function (key) {
var property = this.data.schema.properties[key];
var template = 'edit-' + (property.ui || property.format || property.type);
return template;
},
getDisplayComponent: function (key) {
var property = this.data.schema.properties[key];
var template = 'display-' + (property.ui || property.format || property.type);
return template;
},
show: function (key, value) {
return key !== 'id';
},
valid(schema, key, value) {
var result = {};
if (schema.required) {
result.required = '必须输入' + schema.title;
}
else if (schema.pattern) {
result.pattern.regex = schema.pattern.regex;
result.pattern.message = schema.pattern.message;
}
return result;
},
onSubmit: function () {
}
}
}
</script>