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.
163 lines
7.1 KiB
163 lines
7.1 KiB
<template>
|
|
<layout :htmltitle="title">
|
|
<h1>{{title}}</h1>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<form ref="form" class="'form-horizontal query" @submit.prevent="onSubmit($event)">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<input type="hidden" name="id">
|
|
<div class="form-group row">
|
|
<label for="userName" class="col-sm-2 col-form-label">用户名:</label>
|
|
<div class="col-sm-6 form-control" style="border-color: transparent; height: auto; min-height: calc(2.25rem + 2px);">
|
|
<div mode="edit" title="用户名"><input type="text" id="userName" name="userName" class="form-control"></div>
|
|
<div style="height: 1em;"><span class="text-danger field-validation-valid"></span></div>
|
|
</div>
|
|
<div class="col-sm-4"></div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label for="password" class="col-sm-2 col-form-label">密码:</label>
|
|
<div class="col-sm-6 form-control" style="border-color: transparent; height: auto; min-height: calc(2.25rem + 2px);">
|
|
<div mode="edit" title="密码"><input type="password" id="password" name="password" class="form-control"></div>
|
|
<div style="height: 1em;"><span class="text-danger field-validation-valid"></span></div>
|
|
</div>
|
|
<div class="col-sm-4"></div>
|
|
</div>
|
|
</div>
|
|
<div class="card-footer">
|
|
<div class="row">
|
|
<div class="col-sm-2"></div>
|
|
<div class="col-sm-10"><button type="submit" class="btn btn-primary" @onclick="">确定</button></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</layout>
|
|
</template>
|
|
<script>
|
|
export default {
|
|
props: ['service', 'area', 'entity', 'model', 'id', 'mode'],
|
|
name: 'update',
|
|
data: function () {
|
|
return {
|
|
data: {
|
|
errors: [],
|
|
schema: null,
|
|
model: null,
|
|
data: null
|
|
}
|
|
}
|
|
},
|
|
computed: {
|
|
path: function () {
|
|
return '/IoTCenter/Account/Login';
|
|
},
|
|
action: function () {
|
|
return this.baseUrl + this.path + 'Api'
|
|
},
|
|
name: function () {
|
|
return this.data.schema ? this.data.schema.title : '';
|
|
},
|
|
title: function () {
|
|
return '登录';
|
|
},
|
|
base: function () {
|
|
return this.$route.path.substr(0, this.$route.path.lastIndexOf('/') + 1);
|
|
}
|
|
},
|
|
mounted: function () {
|
|
this.load();
|
|
},
|
|
methods: {
|
|
load: function () {
|
|
var vm = this;
|
|
var url = this.baseUrl + this.path;
|
|
axios.get(url).then(function (response) {
|
|
vm.data = response.data;
|
|
});
|
|
},
|
|
getSchema: function () {
|
|
return this.data.schema;
|
|
},
|
|
getModel: function () {
|
|
return this.data.model;
|
|
},
|
|
getErrors: function () {
|
|
return this.data.errors;
|
|
},
|
|
hasErrors: function (key) {
|
|
key = key.toLowerCase();
|
|
return Enumerable.from(this.getErrors()).any(o => o.key.toLowerCase() === key);
|
|
},
|
|
getValidationSummary: function (excludePropertyErrors) {
|
|
var query = Enumerable.from(this.getErrors());
|
|
if (excludePropertyErrors) {
|
|
query = query.where(o => o.key === '')
|
|
}
|
|
return query.select(o => o.value.errors[0].errorMessage).toArray();
|
|
},
|
|
getPropertyErrors: function (key) {
|
|
key = key.toLowerCase();
|
|
return Enumerable.from(this.getErrors())
|
|
.where(o => o.key.toLowerCase() === key).selectMany(o => o.value.errors).select(o => o.errorMessage).toArray().join(',');
|
|
},
|
|
change: function (name) {
|
|
return this.$validProperty(name);
|
|
},
|
|
hasPermission: function () {
|
|
return true;
|
|
},
|
|
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';
|
|
},
|
|
onSubmit: function (e) {
|
|
var userName = $('#userName').val();
|
|
var password = $('#password').val()
|
|
if (!userName) {
|
|
$('#userName').parents('.form-control').find('.field-validation-valid').text('用户名不能为空');
|
|
}
|
|
else {
|
|
$('#userName').parents('.form-control').find('.field-validation-valid').text('');
|
|
}
|
|
if (!password) {
|
|
$('#password').parents('.form-control').find('.field-validation-valid').text('密码不能为空');
|
|
}
|
|
else {
|
|
$('#password').parents('.form-control').find('.field-validation-valid').text('');
|
|
}
|
|
if (userName && password) {
|
|
var url = this.baseUrl + '/IoTCenter/api/v1/Token/GetToken';
|
|
axios.post(url, { userName: userName, password: password }).then(function (response) {
|
|
if (response.status === 200) {
|
|
if (response.data.errors) {
|
|
this.data = response.data;
|
|
Swal.fire(response.data.errors[0].value.errors[0].errorMessage)
|
|
}
|
|
else {
|
|
store.commit('login', response.data);
|
|
setTimeout(function () {
|
|
router.push('/');
|
|
}, 1000);
|
|
}
|
|
}
|
|
}).catch(function (err) {
|
|
Swal.fire(err.response.data.message);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|