Browse Source

联调注册接口

master
邓宏 2 years ago
parent
commit
5a293a8677
  1. 16
      common/request.js
  2. 96
      pages/home/register.vue
  3. 14
      uni_modules/d-form/components/d-form/d-form.vue

16
common/request.js

@ -3,22 +3,15 @@ import store from "@/store"
export function host(host='default',suffix='/plant_manage'){
var url=process.env.NODE_ENV === 'development'?{
// default:`http://wmyrzw.natappfree.cc` //陈
default:`http://d996zw.natappfree.cc/` //马
default:`http://czixnn.natappfree.cc` //马
// default:`http://192.168.0.116:8080` //孙
}:{
default:`http://qv6mj8.natappfree.cc`
default:``
}
return ({
default:`${url.default}${suffix}`,
imgUrl:`${url.default}/plant_manage/sys/common/static`
})[host]
// return(
// process.env.NODE_ENV === 'development'?{
// default:`http://10.0.0.217${suffix}` //陈
// // default:`http://6h8nxd.natappfree.cc${suffix}` //马
// }:{
// default:`http://qv6mj8.natappfree.cc${suffix}`
// }
// )[host]
}
@ -41,6 +34,7 @@ const request=async function(url,param={}){
}
if(param.file||param.filePath){
console.log(param.suffix,'---suffix----')
var res=await uni.uploadFile({
url:`${param.host||host(undefined,param.suffix)}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
file:param.file||{},
@ -52,7 +46,7 @@ const request=async function(url,param={}){
}).then(data=>({...data[1],data:JSON.parse(data[1].data)}))
}else{
var res=await uni.request({
url:`${param.host||host()}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
url:`${param.host||host(undefined,param.suffix)}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
method:param.method||"get",
data:param.body,
timeout:30*1000,

96
pages/home/register.vue

@ -22,30 +22,106 @@
<template>
<view class="container">
<view style="font-size:52rpx;margin-left:42rpx;">注册</view>
<u-form :model="formData" ref="form" :rules="rules">
<d-form v-for="(v,k) in fields" :key="k" v-bind="v" :field="k"/>
<u-form class="inline" :model="formData" errorType="toast" ref="form" :rules="rules">
<d-form
v-for="(v,k) in fields"
:key="k"
v-bind="v"
:field="k"
@input="formData[k]=$event"
@select="fields[k].value=$event.value.map(v=>v.value);formData[k]=$event.value[0].value"/>
</u-form>
<button class="cu-btn round bg-green shadow submit">注册</button>
<button class="cu-btn round bg-green shadow submit" @click="submit">注册</button>
</view>
</template>
<script>
import request from '@/common/request.js'
export default {
data(){
return{
fields:{
name:{placeholder:"请输入企业名称(中文)"},
code:{placeholder:"请输入统一社会信用代码"},
type:{placeholder:"请选择企业类型",type:"select"},
people:{placeholder:"请输入企业联系人"},
tel:{placeholder:"请输入手机号码"},
password:{placeholder:"请输入密码(6-20位字母和数字的组合)"},
creditCode:{placeholder:"请输入统一社会信用代码"},
type:{placeholder:"请选择企业类型",type:"select",columns:[[]],value:[]},
connectUser:{placeholder:"请输入企业联系人"},
connectPhone:{placeholder:"请输入手机号码"},
password:{placeholder:"请输入密码(6-20位字母和数字的组合)",type:"password"},
},
formData:{
name: "",
creditCode: "",
type: "",
connectUser: "",
connectPhone: "",
password: "",
},
formData:{name:""},
rules:{
name:{required:true, message:"企业名称必填!", trigger:"blur"}
name:{required:true, message:"企业名称必填!", trigger:"blur"},
creditCode:{required:true, validator(rule, val, call){
if(!val)call(new Error('统一社会信用代码必填!'));
else if(!/^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/.test(val))call(new Error('请输入正确的统一社会信用代码格式!'));
else call()
}, trigger:"blur"},
type:{required:true, message:"企业类型必选!", trigger:"blur"},
connectUser:{required:true, message:"企业联系人必填!", trigger:"blur"},
connectPhone:{required:true, validator(rule, val, call){
if(!val)call(new Error("手机号码必填!"));
else if(!/^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(val))call(new Error("请输入正确的手机号码格式!"));
else call()
}, trigger:"blur"},
password:{required:true, validator(rule,val,call){
if(!val)call(new Error('密码必填!'));
else if(!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/.test(val))call(new Error('密码格式为(6-20位字母和数字的组合)!'));
else call();
}, trigger:"blur"},
},
}
},
onload(){
},
onShow(){
this.init()
},
methods:{
async init(){
var res=await request("/common/api/dict/queryDictItemByDictCode",{
method:"post",
params:{dictCode:"company_type"}
})
if(res.statu){
this.fields.type.columns=[res.data]
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取企业类型选项失败!",
showCancel:false,
})
}
},
async submit(){
this.$refs.form.validate().then(async valid=>{
if(valid){
var res=await request("/base/api/plantCompany/register",{
method:"post",
body:this.formData
})
if(res.statu){
uni.showToast({title:"注册成功!"})
setTimeout(()=>{
uni.reLaunch({url:"/"})
},1500)
}else{
uni.showModal({
title:"提示",
content:res.msg||"注册失败!",
showCancel:false,
})
}
}
})
}
}
}
</script>

14
uni_modules/d-form/components/d-form/d-form.vue

@ -147,10 +147,12 @@
color:#FBA83C;
}
&/deep/ {
.u-form-item__body__left__content{
.u-form-item__body__left__content__required{
position:initial;
margin-right:4rpx;
.u-form-item__body__left{
.u-form-item__body__left__content{
.u-form-item__body__left__content__required{
position:initial;
margin-right:4rpx;
}
}
}
.u-form-item__body__right__message{
@ -183,7 +185,7 @@
<template>
<view class="d-form">
<u-form-item :class="{tip:!!tip}" :label="label" :prop="field" :required="required">
<view v-if="/^text$|^number$|^digit$/.test(type)" class="textinput">
<view v-if="/^text$|^number$|^digit$|^password$/.test(type)" class="textinput">
<u-input :placeholder="placeholder||`请输入${label}`" :type="type" :value="value" @input="$emit('input',$event)" @blur="/^number$|^digit$/.test(type) && $emit('input',parseFloat(value)||'')">
<text v-if="suffix" slot="suffix">{{suffix}}</text>
</u-input>
@ -368,7 +370,7 @@ import {dataType} from 'black-knight/lib/config/tools'
},
pickerContent(){//
if(this.type=='select'){
return setPickerVal(this.columns[0], this.value).filter(v=>v).at(-1)?.label||`请选择${this.label}`
return setPickerVal(this.columns[0], this.value).filter(v=>v).at(-1)?.label||this.placeholder||`请选择${this.label}`
}
return ''
},

Loading…
Cancel
Save