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'){ export function host(host='default',suffix='/plant_manage'){
var url=process.env.NODE_ENV === 'development'?{ var url=process.env.NODE_ENV === 'development'?{
// default:`http://wmyrzw.natappfree.cc` //陈 // 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 ({ return ({
default:`${url.default}${suffix}`, default:`${url.default}${suffix}`,
imgUrl:`${url.default}/plant_manage/sys/common/static` imgUrl:`${url.default}/plant_manage/sys/common/static`
})[host] })[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){ if(param.file||param.filePath){
console.log(param.suffix,'---suffix----')
var res=await uni.uploadFile({ var res=await uni.uploadFile({
url:`${param.host||host(undefined,param.suffix)}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`, url:`${param.host||host(undefined,param.suffix)}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
file:param.file||{}, file:param.file||{},
@ -52,7 +46,7 @@ const request=async function(url,param={}){
}).then(data=>({...data[1],data:JSON.parse(data[1].data)})) }).then(data=>({...data[1],data:JSON.parse(data[1].data)}))
}else{ }else{
var res=await uni.request({ 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", method:param.method||"get",
data:param.body, data:param.body,
timeout:30*1000, timeout:30*1000,

96
pages/home/register.vue

@ -22,30 +22,106 @@
<template> <template>
<view class="container"> <view class="container">
<view style="font-size:52rpx;margin-left:42rpx;">注册</view> <view style="font-size:52rpx;margin-left:42rpx;">注册</view>
<u-form :model="formData" ref="form" :rules="rules"> <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"/> <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> </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> </view>
</template> </template>
<script> <script>
import request from '@/common/request.js'
export default { export default {
data(){ data(){
return{ return{
fields:{ fields:{
name:{placeholder:"请输入企业名称(中文)"}, name:{placeholder:"请输入企业名称(中文)"},
code:{placeholder:"请输入统一社会信用代码"}, creditCode:{placeholder:"请输入统一社会信用代码"},
type:{placeholder:"请选择企业类型",type:"select"}, type:{placeholder:"请选择企业类型",type:"select",columns:[[]],value:[]},
people:{placeholder:"请输入企业联系人"}, connectUser:{placeholder:"请输入企业联系人"},
tel:{placeholder:"请输入手机号码"}, connectPhone:{placeholder:"请输入手机号码"},
password:{placeholder:"请输入密码(6-20位字母和数字的组合)"}, password:{placeholder:"请输入密码(6-20位字母和数字的组合)",type:"password"},
},
formData:{
name: "",
creditCode: "",
type: "",
connectUser: "",
connectPhone: "",
password: "",
}, },
formData:{name:""},
rules:{ 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> </script>

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

@ -147,10 +147,12 @@
color:#FBA83C; color:#FBA83C;
} }
&/deep/ { &/deep/ {
.u-form-item__body__left__content{ .u-form-item__body__left{
.u-form-item__body__left__content__required{ .u-form-item__body__left__content{
position:initial; .u-form-item__body__left__content__required{
margin-right:4rpx; position:initial;
margin-right:4rpx;
}
} }
} }
.u-form-item__body__right__message{ .u-form-item__body__right__message{
@ -183,7 +185,7 @@
<template> <template>
<view class="d-form"> <view class="d-form">
<u-form-item :class="{tip:!!tip}" :label="label" :prop="field" :required="required"> <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)||'')"> <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> <text v-if="suffix" slot="suffix">{{suffix}}</text>
</u-input> </u-input>
@ -368,7 +370,7 @@ import {dataType} from 'black-knight/lib/config/tools'
}, },
pickerContent(){// pickerContent(){//
if(this.type=='select'){ 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 '' return ''
}, },

Loading…
Cancel
Save