123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <template>
- <view class="uni-container">
- <uni-forms ref="form" :model="formData" validateTrigger="bind">
- <uni-forms-item name="app_status" label="">
- <uni-easyinput placeholder="app客户端" v-model="formData.app_status"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="user_name" label="">
- <uni-easyinput placeholder="用户名称" v-model="formData.user_name"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="user_brand" label="">
- <uni-easyinput placeholder="手机品牌" v-model="formData.user_brand"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="user_model" label="">
- <uni-easyinput placeholder="手机型号" v-model="formData.user_model"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="api_src" label="">
- <uni-easyinput placeholder="接口请求地址" v-model="formData.api_src"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="request_parameters" label="">
- <uni-easyinput placeholder="请求参数" v-model="formData.request_parameters"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="response_parameters" label="">
- <uni-easyinput placeholder="返回参数" v-model="formData.response_parameters"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="api_status" label="">
- <uni-easyinput placeholder="接口状态" v-model="formData.api_status"></uni-easyinput>
- </uni-forms-item>
- <uni-forms-item name="error_info" label="">
- <uni-easyinput placeholder="接口状态" v-model="formData.error_info"></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/cyt-logs.js';
- const db = uniCloud.database();
- const dbCmd = db.command;
- const dbCollectionName = 'cyt-logs';
- 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 = {
- "app_status": "",
- "user_name": "",
- "user_brand": "",
- "user_model": "",
- "api_src": "",
- "request_parameters": "",
- "response_parameters": "",
- "api_status": "",
- "error_info": ""
- }
- return {
- formData,
- formOptions: {},
- rules: {
- ...getValidator(Object.keys(formData))
- }
- }
- },
- 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).add(value).then((res) => {
- uni.showToast({
- title: '新增成功'
- })
- this.getOpenerEventChannel().emit('refreshData')
- setTimeout(() => uni.navigateBack(), 500)
- }).catch((err) => {
- uni.showModal({
- content: err.message || '请求服务失败',
- showCancel: false
- })
- })
- }
- }
- }
- </script>
|