微信公众号自动登录

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() {
return request({

View File

@ -1,7 +1,7 @@
// 应用全局配置
module.exports = {
//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/',
baseImageUrl: 'https://www.nuoyunr.com/minio',
//wsUrl: 'wss://www.nuoyunr.com/admin-api',

View File

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

View File

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

View File

@ -35,22 +35,27 @@
</template>
<script>
import request from '../../utils/request';
import {
loginApp
} from '@/api/login.js';
import {
import request from '../../utils/request';
import {
loginApp,
} from '@/api/login.js';
import {
setToken,
setTenantId
} from '@/utils/auth.js'
import {
setTenantId,
removeToken
} from '@/utils/auth.js'
import {
login,
getInfo,
getTenantIdByWebsite
} from '@/api/login.js'
export default {
} from '@/api/login.js'
import drawQrcode from "weapp-qrcode";
export default {
data() {
return {
//openId
openId: "",
phoneNumber: "",
baseUrl: this.$baseUrl,
isButtonDisabled: false,
@ -79,9 +84,65 @@
}
},
},
mounted() {},
methods: {
mounted() {
},
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) {
this.sfindex = text
@ -149,7 +210,7 @@
},
goregister() {
uni.navigateTo({
url: '/pages/login/register'
url: '/pages/my/register?openId='+this.openId
})
},
goforgot() {
@ -228,35 +289,35 @@
}, 1000);
},
}
}
}
</script>
<style scoped lang="scss">
.jsq {
.jsq {
border: none !important;
font-size: 14px;
font-weight: 400;
color: #0078FF;
}
}
button {
button {
border: none !important;
background: none !important;
margin: 0px;
display: block;
}
}
button:focus {
button:focus {
color: #0078FF;
outline: none;
box-shadow: none;
}
}
.content {
.content {
box-sizing: border-box;
}
}
.top {
.top {
box-sizing: border-box;
padding: 0px 27px;
padding-top: 100px;
@ -267,9 +328,9 @@
background-position: center;
width: 100%;
// height: 385px;
}
}
.touxiang {
.touxiang {
width: 88px;
height: 88px;
border-radius: 10px;
@ -282,9 +343,9 @@
width: 100%;
height: 100%;
}
}
}
.twotap {
.twotap {
width: 100%;
display: flex;
align-items: center;
@ -296,23 +357,23 @@
color: #666666;
margin-right: 38.5px;
}
}
}
.blck {
.blck {
color: #333333 !important;
font-weight: bold !important;
}
}
.inputs {
.inputs {
box-sizing: border-box;
padding: 16px 0px;
display: flex;
align-items: center;
border-bottom: 2px solid #E8E8E8;
margin-top: 20px;
}
}
.wjworb {
.wjworb {
margin-top: 5px;
width: 100%;
display: flex;
@ -321,9 +382,9 @@
justify-content: flex-end;
align-items: center;
}
}
.dl {
.dl {
width: 90%;
height: 44px;
background: linear-gradient(-46deg, #0853C4 0%, #4282D8 80%);
@ -335,18 +396,18 @@
justify-content: center;
align-items: center;
margin-top: 22px;
}
}
.hging {
.hging {
width: 100%;
text-align: center;
font-size: 14px;
font-weight: 400;
color: #636363;
margin-top: 20px;
}
}
.wx {
.wx {
width: 38px;
height: 38px;
overflow: hidden;
@ -358,17 +419,17 @@
width: 100%;
height: 100%;
}
}
}
.hui {
.hui {
font-size: 10px;
width: 100%;
text-align: center;
font-weight: 400;
color: #666666;
}
}
.dbottom {
.dbottom {
width: 100%;
text-align: center;
font-size: 12px;
@ -379,17 +440,17 @@
display: flex;
align-items: center;
justify-content: center;
}
}
.quanzi {
.quanzi {
width: 14px;
height: 14px;
border: 1px solid #666666;
border-radius: 50%;
margin-right: 10px;
}
}
.lanquanzi {
.lanquanzi {
width: 14px;
height: 14px;
border: 1px solid #0078FF;
@ -397,30 +458,30 @@
margin-right: 10px;
background: #0078FF;
color: white;
}
}
.lan {
.lan {
color: #0078FF;
}
}
.jiuzhong {
.jiuzhong {
width: 90%;
margin: 10px auto;
display: flex;
align-items: center;
}
}
.dist {
.dist {
display: flex;
align-items: center;
margin: 0px 10px;
}
}
.d-zi {
.d-zi {
font-size: 14px;
}
}
.d-qian {
.d-qian {
width: 14px;
height: 14px;
margin-right: 5px;
@ -431,9 +492,9 @@
justify-content: center;
border: 1px solid #666666;
color: white;
}
}
.d-qian-lan {
.d-qian-lan {
width: 14px;
height: 14px;
margin-right: 5px;
@ -445,5 +506,5 @@
background: #0078FF;
border: 1px solid #0078FF;
color: white;
}
}
</style>

View File

@ -5,72 +5,78 @@
<view class="formItem">
<view class="formLabel">姓名</view>
<view class="formContainer">
<input placeholder="请填写你的真实姓名" type="text" />
<input placeholder="请填写你的真实姓名" v-model="formData.cusName" type="text"/>
</view>
</view>
<view class="formItem">
<view class="formLabel">性别</view>
<view class="formContainer">
<radio-group class="radioGroup">
<label class="radio">
<radio activeBackgroundColor="#009EDA" value="r1" checked="true" />
</label>
<label class="radio">
<radio activeBackgroundColor="#009EDA" value="r2" />
<radio-group name="group1" class="radioGroup" :bindchange="radioChange">
<label class="radio" v-for="(item, index) in radioSexItems" :key="item.value">
<radio activeBackgroundColor="#009EDA" :value="item.value" :checked="item.checked"/>
{{item.name}}
</label>
</radio-group>
</view>
</view>
<view class="formItem">
<view class="formLabel">省份</view>
<view class="formLabel">身份证号</view>
<view class="formContainer">
<picker :range="addressRange" mode="multiSelector" @columnchange="addressColumnChangeFun">
<view class="formPicker">
<input class="formPickerInput" type="text" disabled="true" placeholder="请选择所在省份/城市/区" />
<image class="formPickerBtn" src="../../static/icons/homeInfoMore.png" mode="aspectFit">
</image>
<input placeholder="请填写你的身份证号" v-model="formData.idCard" type="text"/>
</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 class="formItem">
<view class="formLabel">详细地址</view>
<view class="formLabel">联系地址</view>
<view class="formContainer">
<picker :range="detailAddress" mode="multiSelector" @columnchange="detailColumnChangeFun">
<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>
<textarea placeholder="请填写你的联系地址" v-model="formData.address" maxlength="300"/>
</view>
</view>
<view class="dl" @click="getlogin()">
<text>注册</text>
</view>
</view>
</view>
</template>
<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: {
VNavigationBar
},
data() {
return {
formData: {
openId: "",
cusName: "",
sex: "",
idCard:"",
phoneNumber:"",
address:"",
},
//
radioSexItems: [
{ name: '男', value: '0', checked: true },
{ name: '女', value: '1', checked: false },
],
detailAddress: [
['a', 'b'],
['b', 'a']
@ -82,7 +88,105 @@
]
};
},
onLoad(e) {
this.formData.openId = e.openId
},
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({
detail
}) {
@ -123,11 +227,10 @@
console.log('上传失败:', e)
}
}
}
}
</script>
<style lang="less" scoped>
.container {
.container {
height: 100%;
display: flex;
flex-direction: column;
@ -185,5 +288,18 @@
width: 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>

View File

@ -26,9 +26,9 @@ const request = config => {
const isTanantId = (config.headers || {}).isTanantId === false
config.header = config.header || {}
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);
return new Promise((resolve, reject) => {
uni.request({