200 lines
5.8 KiB
Vue
200 lines
5.8 KiB
Vue
<template>
|
|
<view class="uni-container">
|
|
<uni-forms ref="form" :model="formData" validateTrigger="bind">
|
|
<uni-forms-item name="create_date" label="">
|
|
<uni-datetime-picker return-type="timestamp" v-model="formData.create_date"></uni-datetime-picker>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="device_uuid" label="">
|
|
<uni-easyinput placeholder="设备唯一标识" v-model="formData.device_uuid"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="ip" label="">
|
|
<uni-easyinput placeholder="ip地址" v-model="formData.ip"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="state" label="">
|
|
<uni-easyinput placeholder="结果:0 失败、1 成功" type="number" v-model="formData.state"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="type" label="">
|
|
<uni-data-checkbox v-model="formData.type" :localdata="formOptions.type_localdata"></uni-data-checkbox>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="ua" label="">
|
|
<uni-easyinput placeholder="userAgent" v-model="formData.ua"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="user_id" label="" required>
|
|
<uni-easyinput placeholder="用户id,参考uni-id-users表" v-model="formData.user_id"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="username" label="">
|
|
<uni-easyinput placeholder="用户名" v-model="formData.username"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="email" label="">
|
|
<uni-easyinput placeholder="邮箱" v-model="formData.email"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="mobile" label="">
|
|
<uni-easyinput placeholder="手机号" v-model="formData.mobile"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<uni-forms-item name="appid" label="">
|
|
<uni-easyinput placeholder="客户端DCloud AppId" v-model="formData.appid"></uni-easyinput>
|
|
</uni-forms-item>
|
|
<view class="uni-button-group">
|
|
<button type="primary" class="uni-button" style="width: 100px;" @click="submit">提交</button>
|
|
<navigator open-type="navigateBack" style="margin-left: 15px;">
|
|
<button class="uni-button" style="width: 100px;">返回</button>
|
|
</navigator>
|
|
</view>
|
|
</uni-forms>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { validator } from '../../js_sdk/validator/uni-id-log.js';
|
|
|
|
const db = uniCloud.database();
|
|
const dbCmd = db.command;
|
|
const dbCollectionName = 'uni-id-log';
|
|
|
|
function getValidator(fields) {
|
|
let result = {}
|
|
for (let key in validator) {
|
|
if (fields.includes(key)) {
|
|
result[key] = validator[key]
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
data() {
|
|
let formData = {
|
|
"create_date": null,
|
|
"device_uuid": "",
|
|
"ip": "",
|
|
"state": null,
|
|
"type": "",
|
|
"ua": "",
|
|
"user_id": "",
|
|
"username": "",
|
|
"email": "",
|
|
"mobile": "",
|
|
"appid": ""
|
|
}
|
|
return {
|
|
formData,
|
|
formOptions: {
|
|
"type_localdata": [
|
|
{
|
|
"value": "logout",
|
|
"text": "logout"
|
|
},
|
|
{
|
|
"value": "login",
|
|
"text": "login"
|
|
},
|
|
{
|
|
"value": "register",
|
|
"text": "register"
|
|
},
|
|
{
|
|
"value": "reset-pwd",
|
|
"text": "reset-pwd"
|
|
},
|
|
{
|
|
"value": "bind-mobile",
|
|
"text": "bind-mobile"
|
|
},
|
|
{
|
|
"value": "bind-weixin",
|
|
"text": "bind-weixin"
|
|
},
|
|
{
|
|
"value": "bind-qq",
|
|
"text": "bind-qq"
|
|
},
|
|
{
|
|
"value": "bind-apple",
|
|
"text": "bind-apple"
|
|
},
|
|
{
|
|
"value": "bind-alipay",
|
|
"text": "bind-alipay"
|
|
}
|
|
]
|
|
},
|
|
rules: {
|
|
...getValidator(Object.keys(formData))
|
|
}
|
|
}
|
|
},
|
|
onLoad(e) {
|
|
if (e.id) {
|
|
const id = e.id
|
|
this.formDataId = id
|
|
this.getDetail(id)
|
|
}
|
|
},
|
|
onReady() {
|
|
this.$refs.form.setRules(this.rules)
|
|
},
|
|
methods: {
|
|
|
|
/**
|
|
* 验证表单并提交
|
|
*/
|
|
submit() {
|
|
uni.showLoading({
|
|
mask: true
|
|
})
|
|
this.$refs.form.validate().then((res) => {
|
|
return this.submitForm(res)
|
|
}).catch(() => {
|
|
}).finally(() => {
|
|
uni.hideLoading()
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 提交表单
|
|
*/
|
|
submitForm(value) {
|
|
// 使用 clientDB 提交数据
|
|
return db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => {
|
|
uni.showToast({
|
|
title: '修改成功'
|
|
})
|
|
this.getOpenerEventChannel().emit('refreshData')
|
|
setTimeout(() => uni.navigateBack(), 500)
|
|
}).catch((err) => {
|
|
uni.showModal({
|
|
content: err.message || '请求服务失败',
|
|
showCancel: false
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 获取表单数据
|
|
* @param {Object} id
|
|
*/
|
|
getDetail(id) {
|
|
uni.showLoading({
|
|
mask: true
|
|
})
|
|
db.collection(dbCollectionName).doc(id).field("create_date,device_uuid,ip,state,type,ua,user_id,username,email,mobile,appid").get().then((res) => {
|
|
const data = res.result.data[0]
|
|
if (data) {
|
|
this.formData = data
|
|
|
|
}
|
|
}).catch((err) => {
|
|
uni.showModal({
|
|
content: err.message || '请求服务失败',
|
|
showCancel: false
|
|
})
|
|
}).finally(() => {
|
|
uni.hideLoading()
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|