微信公众号自动登录

This commit is contained in:
Vinjor 2024-09-24 18:32:59 +08:00
parent 05e7447f70
commit ed71f35fcb
7 changed files with 783 additions and 588 deletions

View File

@ -18,6 +18,14 @@ export function login(username, password, code, uuid) {
}) })
} }
// 微信登录
export function wechatLogin(data) {
return request({
'url': '/weChat/wechatLogin',
'method': 'post',
'data':data
})
}
// 获取用户详细信息 // 获取用户详细信息
export function getInfo() { export function getInfo() {
return request({ return request({

View File

@ -1,7 +1,7 @@
// 应用全局配置 // 应用全局配置
module.exports = { module.exports = {
//baseUrl: 'https://www.nuoyunr.com/admin-api', //baseUrl: 'https://www.nuoyunr.com/admin-api',
baseUrl: 'http://192.168.1.4:48080/userClient', baseUrl: 'https://3w823u8516.vicp.fun',
imagesUrl: 'http://shequ.0315e.com/static/images/pages/', imagesUrl: 'http://shequ.0315e.com/static/images/pages/',
baseImageUrl: 'https://www.nuoyunr.com/minio', baseImageUrl: 'https://www.nuoyunr.com/minio',
//wsUrl: 'wss://www.nuoyunr.com/admin-api', //wsUrl: 'wss://www.nuoyunr.com/admin-api',

View File

@ -69,5 +69,15 @@
"uniStatistics" : { "uniStatistics" : {
"enable" : false "enable" : false
}, },
"h5" : {
"router" : {
"base" : "/lanan-repair"
},
"devServer" : {
"port" : 8080,
"disableHostCheck" : true,
"https" : false
}
},
"vueVersion" : "2" "vueVersion" : "2"
} }

View File

@ -6,12 +6,12 @@
// "navigationBarTitleText": "uni-app" // "navigationBarTitleText": "uni-app"
// } // }
// }, // },
// { {
// "path": "pages/login/login", "path": "pages/login/login",
// "style": { "style": {
// "navigationBarTitleText": "uni-app" "navigationBarTitleText": "uni-app"
// } }
// }, },
{ {
"path" : "pages/home/home", "path" : "pages/home/home",
"style" : "style" :

View File

@ -35,22 +35,27 @@
</template> </template>
<script> <script>
import request from '../../utils/request'; import request from '../../utils/request';
import { import {
loginApp loginApp,
} from '@/api/login.js'; } from '@/api/login.js';
import { import {
setToken, setToken,
setTenantId setTenantId,
} from '@/utils/auth.js' removeToken
import { } from '@/utils/auth.js'
import {
login, login,
getInfo, getInfo,
getTenantIdByWebsite getTenantIdByWebsite
} from '@/api/login.js' } from '@/api/login.js'
export default { import drawQrcode from "weapp-qrcode";
export default {
data() { data() {
return { return {
//openId
openId: "",
phoneNumber: "", phoneNumber: "",
baseUrl: this.$baseUrl, baseUrl: this.$baseUrl,
isButtonDisabled: false, isButtonDisabled: false,
@ -79,9 +84,65 @@
} }
}, },
}, },
mounted() {}, mounted() {
methods: { },
created(){
//token
removeToken()
/*2.微信公众平台自动登录*/
let code = this.getUrlCode('code')
if (code !== null && code !== "") {
//
this.getOpenidAndUserinfo(code)
} else {
uni.showToast({
title: '未获取到授权信息,请重新进入!!',
icon: 'none'
})
}
},
onShow() {
},
methods: {
/**
* 微信自动登录
* @param {Object} code 用户code
*/
async getOpenidAndUserinfo(code) {
await request({
url: '/userClient/weChat/wechatLogin',
method: 'get',
params: {code:code}
}).then((res) => {
if (res.code==200) {
if(res.data.hasOwnProperty("accessToken")){
setToken(res.data.accessToken)
uni.reLaunch({
url: '/pages/home/home'
})
}else{
//
this.openId = res.data
//
this.goregister()
}
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
})
},
/**
* 获取路径中的参数
* @param {Object} name
*/
getUrlCode(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
},
setidentity(text) { setidentity(text) {
this.sfindex = text this.sfindex = text
@ -149,7 +210,7 @@
}, },
goregister() { goregister() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/register' url: '/pages/my/register?openId='+this.openId
}) })
}, },
goforgot() { goforgot() {
@ -228,35 +289,35 @@
}, 1000); }, 1000);
}, },
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.jsq { .jsq {
border: none !important; border: none !important;
font-size: 14px; font-size: 14px;
font-weight: 400; font-weight: 400;
color: #0078FF; color: #0078FF;
} }
button { button {
border: none !important; border: none !important;
background: none !important; background: none !important;
margin: 0px; margin: 0px;
display: block; display: block;
} }
button:focus { button:focus {
color: #0078FF; color: #0078FF;
outline: none; outline: none;
box-shadow: none; box-shadow: none;
} }
.content { .content {
box-sizing: border-box; box-sizing: border-box;
} }
.top { .top {
box-sizing: border-box; box-sizing: border-box;
padding: 0px 27px; padding: 0px 27px;
padding-top: 100px; padding-top: 100px;
@ -267,9 +328,9 @@
background-position: center; background-position: center;
width: 100%; width: 100%;
// height: 385px; // height: 385px;
} }
.touxiang { .touxiang {
width: 88px; width: 88px;
height: 88px; height: 88px;
border-radius: 10px; border-radius: 10px;
@ -282,9 +343,9 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
} }
.twotap { .twotap {
width: 100%; width: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
@ -296,23 +357,23 @@
color: #666666; color: #666666;
margin-right: 38.5px; margin-right: 38.5px;
} }
} }
.blck { .blck {
color: #333333 !important; color: #333333 !important;
font-weight: bold !important; font-weight: bold !important;
} }
.inputs { .inputs {
box-sizing: border-box; box-sizing: border-box;
padding: 16px 0px; padding: 16px 0px;
display: flex; display: flex;
align-items: center; align-items: center;
border-bottom: 2px solid #E8E8E8; border-bottom: 2px solid #E8E8E8;
margin-top: 20px; margin-top: 20px;
} }
.wjworb { .wjworb {
margin-top: 5px; margin-top: 5px;
width: 100%; width: 100%;
display: flex; display: flex;
@ -321,9 +382,9 @@
justify-content: flex-end; justify-content: flex-end;
align-items: center; align-items: center;
} }
.dl { .dl {
width: 90%; width: 90%;
height: 44px; height: 44px;
background: linear-gradient(-46deg, #0853C4 0%, #4282D8 80%); background: linear-gradient(-46deg, #0853C4 0%, #4282D8 80%);
@ -335,18 +396,18 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
margin-top: 22px; margin-top: 22px;
} }
.hging { .hging {
width: 100%; width: 100%;
text-align: center; text-align: center;
font-size: 14px; font-size: 14px;
font-weight: 400; font-weight: 400;
color: #636363; color: #636363;
margin-top: 20px; margin-top: 20px;
} }
.wx { .wx {
width: 38px; width: 38px;
height: 38px; height: 38px;
overflow: hidden; overflow: hidden;
@ -358,17 +419,17 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
} }
.hui { .hui {
font-size: 10px; font-size: 10px;
width: 100%; width: 100%;
text-align: center; text-align: center;
font-weight: 400; font-weight: 400;
color: #666666; color: #666666;
} }
.dbottom { .dbottom {
width: 100%; width: 100%;
text-align: center; text-align: center;
font-size: 12px; font-size: 12px;
@ -379,17 +440,17 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.quanzi { .quanzi {
width: 14px; width: 14px;
height: 14px; height: 14px;
border: 1px solid #666666; border: 1px solid #666666;
border-radius: 50%; border-radius: 50%;
margin-right: 10px; margin-right: 10px;
} }
.lanquanzi { .lanquanzi {
width: 14px; width: 14px;
height: 14px; height: 14px;
border: 1px solid #0078FF; border: 1px solid #0078FF;
@ -397,30 +458,30 @@
margin-right: 10px; margin-right: 10px;
background: #0078FF; background: #0078FF;
color: white; color: white;
} }
.lan { .lan {
color: #0078FF; color: #0078FF;
} }
.jiuzhong { .jiuzhong {
width: 90%; width: 90%;
margin: 10px auto; margin: 10px auto;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.dist { .dist {
display: flex; display: flex;
align-items: center; align-items: center;
margin: 0px 10px; margin: 0px 10px;
} }
.d-zi { .d-zi {
font-size: 14px; font-size: 14px;
} }
.d-qian { .d-qian {
width: 14px; width: 14px;
height: 14px; height: 14px;
margin-right: 5px; margin-right: 5px;
@ -431,9 +492,9 @@
justify-content: center; justify-content: center;
border: 1px solid #666666; border: 1px solid #666666;
color: white; color: white;
} }
.d-qian-lan { .d-qian-lan {
width: 14px; width: 14px;
height: 14px; height: 14px;
margin-right: 5px; margin-right: 5px;
@ -445,5 +506,5 @@
background: #0078FF; background: #0078FF;
border: 1px solid #0078FF; border: 1px solid #0078FF;
color: white; color: white;
} }
</style> </style>

View File

@ -5,72 +5,78 @@
<view class="formItem"> <view class="formItem">
<view class="formLabel">姓名</view> <view class="formLabel">姓名</view>
<view class="formContainer"> <view class="formContainer">
<input placeholder="请填写你的真实姓名" type="text" /> <input placeholder="请填写你的真实姓名" v-model="formData.cusName" type="text"/>
</view> </view>
</view> </view>
<view class="formItem"> <view class="formItem">
<view class="formLabel">性别</view> <view class="formLabel">性别</view>
<view class="formContainer"> <view class="formContainer">
<radio-group class="radioGroup"> <radio-group name="group1" class="radioGroup" :bindchange="radioChange">
<label class="radio"> <label class="radio" v-for="(item, index) in radioSexItems" :key="item.value">
<radio activeBackgroundColor="#009EDA" value="r1" checked="true" /> <radio activeBackgroundColor="#009EDA" :value="item.value" :checked="item.checked"/>
</label> {{item.name}}
<label class="radio">
<radio activeBackgroundColor="#009EDA" value="r2" />
</label> </label>
</radio-group> </radio-group>
</view> </view>
</view> </view>
<view class="formItem"> <view class="formItem">
<view class="formLabel">省份</view> <view class="formLabel">身份证号</view>
<view class="formContainer"> <view class="formContainer">
<picker :range="addressRange" mode="multiSelector" @columnchange="addressColumnChangeFun"> <input placeholder="请填写你的身份证号" v-model="formData.idCard" type="text"/>
<view class="formPicker">
<input class="formPickerInput" type="text" disabled="true" placeholder="请选择所在省份/城市/区" />
<image class="formPickerBtn" src="../../static/icons/homeInfoMore.png" mode="aspectFit">
</image>
</view> </view>
</picker> </view>
<!-- <view class="formItem">-->
<!-- <view class="formLabel">生日</view>-->
<!-- <view class="formContainer">-->
<!-- <picker mode="date" :value="formData.birthday" start="1900-01-01" end="2050-12-12" :bindchange="bindDateChange">-->
<!-- </picker>-->
<!-- </view>-->
<!-- </view>-->
<view class="formItem">
<view class="formLabel">手机号</view>
<view class="formContainer">
<input placeholder="请填写你的手机号" v-model="formData.phoneNumber" type="text"/>
</view> </view>
</view> </view>
<view class="formItem"> <view class="formItem">
<view class="formLabel">详细地址</view> <view class="formLabel">联系地址</view>
<view class="formContainer"> <view class="formContainer">
<picker :range="detailAddress" mode="multiSelector" @columnchange="detailColumnChangeFun"> <textarea placeholder="请填写你的联系地址" v-model="formData.address" maxlength="300"/>
<view class="formPicker">
<input class="formPickerInput" type="text" disabled="true" placeholder="请选择所在街道/小区" />
<image class="formPickerBtn" src="../../static/icons/homeInfoMore.png" mode="aspectFit">
</image>
</view>
</picker>
</view>
</view>
<view class="formItem">
<view class="formLabel">上传图片</view>
<view class="formContainer">
<view class="">
<uni-file-picker :image-styles="{width: 80, height: 80}" v-model="imageValue"
fileMediatype="image" limit="1" mode="grid" @select="select" @progress="progress"
@success="success" @fail="fail">
<image style="width: 160rpx;height: 160rpx;" src="../../static/icons/addImageIcon.png"
mode="aspectFit"></image>
</uni-file-picker>
</view> </view>
</view> </view>
<view class="dl" @click="getlogin()">
<text>注册</text>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import VNavigationBar from '@/components/VNavigationBar.vue' import VNavigationBar from '@/components/VNavigationBar.vue'
import request from "../../utils/request";
import {
setToken,
} from '@/utils/auth.js'
export default { export default {
components: { components: {
VNavigationBar VNavigationBar
}, },
data() { data() {
return { return {
formData: {
openId: "",
cusName: "",
sex: "",
idCard:"",
phoneNumber:"",
address:"",
},
//
radioSexItems: [
{ name: '男', value: '0', checked: true },
{ name: '女', value: '1', checked: false },
],
detailAddress: [ detailAddress: [
['a', 'b'], ['a', 'b'],
['b', 'a'] ['b', 'a']
@ -82,7 +88,105 @@
] ]
}; };
}, },
onLoad(e) {
this.formData.openId = e.openId
},
methods: { methods: {
/**
* 注册
*/
async getlogin(){
//
if(this.checkForm()){
//
this.formData.sex = this.radioSexItems.filter(item => item.checked ===true)[0].value;
await request({
url: '/base/custom-app/register',
method: 'post',
data: this.formData
}).then((res) => {
if (res.code==200) {
if(res.data.hasOwnProperty("accessToken")){
setToken(res.data.accessToken)
uni.reLaunch({
url: '/pages/home/home'
})
}
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
})
}
},
checkForm(){
if(""==this.formData.cusName){
uni.showToast({
title: '请填写姓名',
icon: 'none'
})
return false
}
if(""==this.formData.idCard || !this.isValidID(this.formData.idCard)){
uni.showToast({
title: '请填写正确的身份证号',
icon: 'none'
})
return false
}
if(""==this.formData.phoneNumber || !this.isValidPhoneNumber(this.formData.phoneNumber)){
uni.showToast({
title: '请填写手机号',
icon: 'none'
})
return false
}
if(""==this.formData.address){
uni.showToast({
title: '请填写联系地址',
icon: 'none'
})
return false
}
return true;
},
/**
* 校验身份证号是否合法
* @param id
* @returns {boolean}
*/
isValidID(id) {
const regex = /^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/;
return regex.test(id);
},
/**
* 校验手机号
* @param phoneNumber
* @returns {boolean}
*/
isValidPhoneNumber(phoneNumber) {
const regex = /^1[3-9]\d{9}$/;
return regex.test(phoneNumber);
},
bindDateChange(e) {
this.formData.birthday = e.detail.value;
},
radioChange: function(e) {
let radioItems = this.radioSexItems;
for (let i = 0, len = radioItems.length; i < len; ++i) {
radioItems[i].checked = radioItems[i].value === e.detail.value;
}
this.radioSexItems = radioItems;
},
submit() {
this.$refs.form.validate().then(res => {
console.log('表单数据信息:', res);
}).catch(err => {
console.log('表单错误信息:', err);
})
},
detailColumnChangeFun({ detailColumnChangeFun({
detail detail
}) { }) {
@ -123,11 +227,10 @@
console.log('上传失败:', e) console.log('上传失败:', e)
} }
} }
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.container { .container {
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -185,5 +288,18 @@
width: 28rpx; width: 28rpx;
height: 28rpx; height: 28rpx;
} }
} }
.dl {
width: 90%;
height: 44px;
background: linear-gradient(-46deg, #0853C4 0%, #4282D8 80%);
border-radius: 5px;
margin: 0 auto;
font-size: 16px;
color: #FFFFFF;
display: flex;
justify-content: center;
align-items: center;
margin-top: 22px;
}
</style> </style>

View File

@ -26,9 +26,9 @@ const request = config => {
const isTanantId = (config.headers || {}).isTanantId === false const isTanantId = (config.headers || {}).isTanantId === false
config.header = config.header || {} config.header = config.header || {}
if(getTenantId() && !isTanantId){ if(getTenantId() && !isTanantId){
config.header['Tenant-Id'] = getTenantId() config.header['tenant-id'] = getTenantId()
} }
config.header['Tenant-Id'] = 180 config.header['tenant-id'] = 180
console.log(config.header,424242); console.log(config.header,424242);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({