微信登录

This commit is contained in:
zpc 2025-07-06 14:00:09 +08:00
parent deb4471299
commit 531f29b7be
13 changed files with 1609 additions and 1213 deletions

View File

@ -177,22 +177,15 @@ class BasePlatform {
];
if (uni.getStorageSync('token') != null && uni.getStorageSync('token') != "") {
m.push({
id: 8,
show: true,
title: '注销账号',
icon: 'my/s10.png',
path: '/pages/user/cancel-account-page',
handler: this.navigateToPath.bind(this)
}),
m.push({
id: 8,
show: true,
title: '退出登录',
icon: 'my/exit.png',
path: '',
handler: this.handleLogout.bind(this)
})
title: '退出登录',
icon: 'my/exit.png',
path: '',
handler: this.handleLogout.bind(this)
})
}
const customServiceMenu = {
id: 10,
@ -262,6 +255,12 @@ class BasePlatform {
getPrivacyAgreement() {
navigateTo('/pages/guize/guize', { type: 5 })
}
/**
* 获取功能权限
*/
getPermission(functionName) {
return true;
}
}
export default BasePlatform;

View File

@ -1,13 +1,33 @@
import BasePlatform from './BasePlatform';
import H5Platform from './H5Platform';
import { webAppPay } from '@/common/webapp.js'
import { parseQueryString } from '@/common/util'
function versionToNumber(versionString) {
// 移除所有点号并转换为数字
return parseInt(versionString.split('.').join(''), 10);
}
class NewWebAppPlatform extends H5Platform {
constructor() {
super();
this.code = 'WEB_APP_ANDROID';
this.env = 'web_app';
this.app_version = 100;
let location = window.location.href;
const params = parseQueryString(location);
if (params['version'] != null) {
uni.setStorageSync('app_version', params['version']);
let _appversion = params['version'] ?? "1.0.0";
if (_appversion.indexOf(".") > -1) {
_appversion = versionToNumber(_appversion);
this.app_version = _appversion;
}
}
if (params['os'] != null) {
uni.setStorageSync('app_os', params['os']);
}
}
share({ title, desc, image, url }) {
console.log(`H5分享${title} - ${desc}`);
@ -83,5 +103,23 @@ class NewWebAppPlatform extends H5Platform {
getVersion() {
return uni.getStorageSync('version') == '' ? '1.0.0' : uni.getStorageSync('version');
}
/**
* 获取功能权限
*/
getPermission(functionName) {
const appPermission = {
wxLogin: 101
};
let _functionVersion = appPermission[functionName];
if (_functionVersion != null) {
//如果当前app权限大于等于功能权限版本则返回true
console.log('验证功能权限', functionName, _functionVersion, this.app_version, this.app_version >= _functionVersion);
return this.app_version >= _functionVersion;
}
return false;
}
}
export default NewWebAppPlatform;

View File

@ -15,4 +15,17 @@ export const getUserInfo = async () => {
} else {
return null;
}
};
};
/**
* 微信APP登录
* @param {String} unionId 微信APP unionId
* @param {String} nickname 微信APP 昵称
* @param {String} headimg 微信APP 头像
* @param {Number} pid 推广码
* @returns {Promise} 是否成功
*/
export const wxAppLogin = async (unionId, nickname, headimg, pid = 0) => {
const res = await RequestManager.post('/wx_app_login', { unionId, nickname, headimg, pid });
return res;
}

View File

@ -33,6 +33,11 @@ window.yds_postMessage = function (data) {
return;
}
console.log('回调不存在');
return;
}
if (_ydsApp.callback[data.callback]) {
_ydsApp.callback[data.callback](data.data);
delete _ydsApp.callback[data.callback];
}
}
//返回按钮
@ -77,4 +82,22 @@ export const webAppPageUrl = (url, isHome) => {
data: { page: url, isHome: isHome },
}
})
}
export const sendWxAppLogin = () => {
return new Promise((resolve, reject) => {
if (!window.ydsApp) {
reject('ydsApp未加载');
return;
}
let callback = generateRandomString(16);
_ydsApp.callback[callback] = resolve;
ydsApp.postMessage({
data: {
action: 'wxAppLogin',
data: {},
callback: callback
}
});
});
}

View File

@ -5,6 +5,7 @@ import common from '@/common/common.js'
// #ifdef H5
import { home } from '@/common/webapp.js'
import ydsMixin from '@/common/ydsmixin.js'
console.log(window.location.href);
// #endif
import {
gotopage

View File

@ -188,7 +188,9 @@
"enable" : false
},
"devServer" : {
"https" : false
"https" : true,
"port" : 3001,
"disableHostCheck" : true
},
"template" : "index.html"
},

View File

@ -94,7 +94,6 @@ export default {
//
if (this.userinfo != null && this.userinfo.ut == 2) {
//
const testMode = uni.getStorageSync('test_mode_status');
if (testMode) {
@ -111,9 +110,9 @@ export default {
}
},
handleIconClick() {
if (this.userinfo && this.userinfo.ut == 2) {
const now = new Date().getTime();
// 2
if (this.clickCount === 0 || now - this.lastClickTime > 2000) {
this.clickCount = 1;

View File

@ -30,8 +30,6 @@
<!-- 今日推荐 -->
<view class="flex yqhy" v-if="tuijian.length > 0" style="margin-top: 30rpx; flex-direction: column">
<!-- <image class="img100" style=" display: flex; justify-content: center;"
:src="$img1('/image/a6548-pw1cx.webp')"></image> -->
<text style="color: black; font-weight: 600; margin-bottom: 20rpx">今日推荐</text>
<view class="flex row align-center"
style="width: 100%; height: 230rpx; justify-content: space-between; overflow: auto;">
@ -50,7 +48,7 @@
<view class="qbt_con" v-if="tabCur > -1">
<view v-for="(item, index) in listdata" :key="index" class="qbt_con_item" @click="todetails(item)">
<view class="list_1 center" style="background-color: #d8d8d8;border-radius: 16rpx 16rpx 0rpx 0rpx;">
<view class="list_1 center" style="background-color: #fff;border-radius: 16rpx 16rpx 0rpx 0rpx;">
<image :src="item.imgurl" mode="aspectFill"></image>
</view>
<view class="list_2">

View File

@ -1,6 +1,5 @@
<template>
<view class="box">
<!-- <uni-popup ref="popup" type="bottom"> -->
<view class="header">
<image :src="$img1('common/logo.png?x=1')"></image>
</view>

View File

@ -26,6 +26,13 @@
<input disabled :value="uid" />
</view>
</view>
<view class="form-item">
<view class="form-label">手机号:</view>
<view class="form-input">
<input disabled :value="phoneNumber" placeholder="暂未绑定手机号" />
</view>
</view>
</view>
<view class="submit-btn" @click="updateUserInfo">确认修改</view>
@ -33,285 +40,288 @@
</template>
<script>
export default {
data() {
return {
statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
avatarUrl: "",
nickname: "",
headimg_status: false,
id: "",
uid: "",
imageBase64: "",
};
},
export default {
data() {
return {
statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
avatarUrl: "",
nickname: "",
headimg_status: false,
id: "",
uid: "",
imageBase64: "",
phoneNumber: "",
unionid: ""
};
},
onLoad() {
this.initUserInfo();
},
onLoad() {
this.initUserInfo();
},
methods: {
onClickAvatar() {
//#ifdef APP
uni.chooseImage({
count: 1,
sourceType: ["album"],
success: async (res) => {
console.log(res);
// this.
this.avatarUrl = res.tempFilePaths[0];
this.headimg_status = true;
const rrrrr = await this.imageToBase64Plus(this.avatarUrl);
console.log(rrrrr, "rrrrr");
this.imageBase64 = rrrrr;
// this.convertToBase64(this.avatarUrl);
}
})
//#endif
},
/**
* 初始化用户信息
*/
initUserInfo() {
const userInfo = uni.getStorageSync("userinfo");
if (userInfo) {
this.avatarUrl = userInfo.headimg || "";
this.nickname = userInfo.nickname || "";
this.id = userInfo.ID;
this.uid = userInfo.uid;
}
},
/**
* 返回上一页
*/
back() {
uni.navigateBack();
},
/**
* 获取昵称
*/
getnickname(e) {
this.nickname = e.detail.value;
},
/**
* 选择头像
*/
onChooseAvatar(e) {
if (e && e.detail && e.detail.avatarUrl) {
this.avatarUrl = e.detail.avatarUrl;
methods: {
onClickAvatar() {
//#ifdef APP
uni.chooseImage({
count: 1,
sourceType: ["album"],
success: async (res) => {
console.log(res);
// this.
this.avatarUrl = res.tempFilePaths[0];
this.headimg_status = true;
this.convertToBase64(this.avatarUrl);
const rrrrr = await this.imageToBase64Plus(this.avatarUrl);
console.log(rrrrr, "rrrrr");
this.imageBase64 = rrrrr;
// this.convertToBase64(this.avatarUrl);
}
},
})
//#endif
/**
* 将图片转换为Base64
*/
convertToBase64(filePath) {
console.log(filePath);
uni.getFileSystemManager().readFile({
filePath: filePath,
encoding: "base64",
success: (res) => {
this.imageBase64 = "data:image/png;base64," + res.data;
},
fail: (err) => {
console.error("读取文件失败:", err);
uni.showToast({
title: "图片处理失败",
icon: "none",
});
},
});
},
imageToBase64Plus(filePath) {
return new Promise((resolve, reject) => {
//#ifdef APP
plus.io.resolveLocalFileSystemURL(filePath, entry => {
entry.file(file => {
const fileReader = new plus.io.FileReader();
fileReader.onloadend = function(e) {
const base64 = e.target.result;
resolve(base64);
};
fileReader.readAsDataURL(file);
}, reject);
}, reject);
//#endif
});
},
/**
* 更新用户信息
*/
updateUserInfo() {
if (!this.nickname) {
},
/**
* 初始化用户信息
*/
initUserInfo() {
const userInfo = uni.getStorageSync("userinfo");
if (userInfo) {
this.avatarUrl = userInfo.headimg || "";
this.nickname = userInfo.nickname || "";
this.id = userInfo.ID;
this.uid = userInfo.uid;
this.phoneNumber = userInfo.mobile || "";
}
},
/**
* 返回上一页
*/
back() {
uni.navigateBack();
},
/**
* 获取昵称
*/
getnickname(e) {
this.nickname = e.detail.value;
},
/**
* 选择头像
*/
onChooseAvatar(e) {
if (e && e.detail && e.detail.avatarUrl) {
this.avatarUrl = e.detail.avatarUrl;
this.headimg_status = true;
this.convertToBase64(this.avatarUrl);
}
},
/**
* 将图片转换为Base64
*/
convertToBase64(filePath) {
console.log(filePath);
uni.getFileSystemManager().readFile({
filePath: filePath,
encoding: "base64",
success: (res) => {
this.imageBase64 = "data:image/png;base64," + res.data;
},
fail: (err) => {
console.error("读取文件失败:", err);
uni.showToast({
title: "请输入昵称",
title: "图片处理失败",
icon: "none",
});
return;
}
},
});
},
imageToBase64Plus(filePath) {
return new Promise((resolve, reject) => {
//#ifdef APP
plus.io.resolveLocalFileSystemURL(filePath, entry => {
entry.file(file => {
const fileReader = new plus.io.FileReader();
fileReader.onloadend = function (e) {
const base64 = e.target.result;
resolve(base64);
};
fileReader.readAsDataURL(file);
}, reject);
}, reject);
//#endif
});
},
const data = {
nickname: this.nickname,
headimg: this.avatarUrl,
imagebase: this.imageBase64,
};
/**
* 更新用户信息
*/
updateUserInfo() {
if (!this.nickname) {
uni.showToast({
title: "请输入昵称",
icon: "none",
});
return;
}
this.$request
.post("update_userinfo", data)
.then((res) => {
if (res.status === 1) {
//
const userInfo = uni.getStorageSync("userinfo") || {};
userInfo.nickname = this.nickname;
userInfo.headimg = this.avatarUrl;
uni.setStorageSync("userinfo", userInfo);
const data = {
nickname: this.nickname,
headimg: this.avatarUrl,
imagebase: this.imageBase64,
};
uni.showToast({
title: "修改成功",
icon: "success",
});
this.$request
.post("update_userinfo", data)
.then((res) => {
if (res.status === 1) {
//
const userInfo = uni.getStorageSync("userinfo") || {};
userInfo.nickname = this.nickname;
userInfo.headimg = this.avatarUrl;
uni.setStorageSync("userinfo", userInfo);
//
setTimeout(() => {
this.$customRouter.navigateTo("./index", {}, 'redirectTo');
}, 1000);
} else {
uni.showToast({
title: res.msg || "修改失败",
icon: "none",
});
}
})
.catch((err) => {
uni.showToast({
title: "网络请求失败",
title: "修改成功",
icon: "success",
});
//
setTimeout(() => {
this.$customRouter.navigateTo("./index", {}, 'redirectTo');
}, 1000);
} else {
uni.showToast({
title: res.msg || "修改失败",
icon: "none",
});
console.error(err);
}
})
.catch((err) => {
uni.showToast({
title: "网络请求失败",
icon: "none",
});
},
console.error(err);
});
},
};
},
};
</script>
<style lang="scss">
.content {
width: 100vw;
height: 100vh;
box-sizing: border-box;
color: #fff;
display: flex;
background-color: #FFFFFF;
flex-direction: column;
}
.content {
width: 100vw;
height: 100vh;
box-sizing: border-box;
color: #fff;
display: flex;
background-color: #FFFFFF;
flex-direction: column;
}
.user-avatar {
padding: 80rpx 0 60rpx 0;
text-align: center;
position: relative;
.user-avatar {
padding: 80rpx 0 60rpx 0;
text-align: center;
position: relative;
.avatar-title {
font-size: 24rpx;
color: #8A8A8A;
position: absolute;
top: 280rpx;
left: 50%;
transform: translateX(-50%);
}
.avatar-wrapper {
width: 165rpx;
height: 165rpx;
margin: auto;
border-radius: 128rpx;
overflow: hidden;
border: 1rpx solid #F3F3F3;
background-color: transparent;
padding: 0;
line-height: normal;
display: flex;
align-items: center;
justify-content: center;
&::after {
border: none;
}
.avatar {
width: 160rpx;
height: 160rpx;
border-radius: 50%;
}
}
.camera-icon {
width: 42rpx;
height: 42rpx;
position: relative;
bottom: 40rpx;
left: 60rpx;
}
}
.form-container {
width: 690rpx;
margin: 0 auto;
}
.form-item {
display: flex;
padding: 30rpx 0;
position: relative;
&::after {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2rpx;
background: #F3F3F3;
}
.form-label {
width: 120rpx;
font-size: 24rpx;
color: #8A8A8A;
}
.form-input {
flex: 1;
input {
flex: 1;
text-align: right;
font-size: 24rpx;
color: #333333;
}
}
}
.submit-btn {
width: 244rpx;
height: 72rpx;
background: #333333;
border-radius: 16rpx;
// border: 2rpx solid #ffffff;
.avatar-title {
font-size: 24rpx;
color: #D8FD24;
margin: 200rpx auto 0;
color: #8A8A8A;
position: absolute;
top: 280rpx;
left: 50%;
transform: translateX(-50%);
}
.avatar-wrapper {
width: 165rpx;
height: 165rpx;
margin: auto;
border-radius: 128rpx;
overflow: hidden;
border: 1rpx solid #F3F3F3;
background-color: transparent;
padding: 0;
line-height: normal;
display: flex;
align-items: center;
justify-content: center;
&::after {
border: none;
}
.avatar {
width: 170rpx;
height: 160rpx;
border-radius: 50%;
}
}
.camera-icon {
width: 42rpx;
height: 42rpx;
position: relative;
bottom: 40rpx;
left: 60rpx;
}
}
.form-container {
width: 690rpx;
margin: 0 auto;
}
.form-item {
display: flex;
padding: 30rpx 0;
position: relative;
&::after {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2rpx;
background: #F3F3F3;
}
.form-label {
width: 150rpx;
font-size: 24rpx;
color: #8A8A8A;
}
.form-input {
flex: 1;
input {
flex: 1;
text-align: right;
font-size: 24rpx;
color: #333333;
}
}
}
.submit-btn {
width: 244rpx;
height: 72rpx;
background: #333333;
border-radius: 16rpx;
// border: 2rpx solid #ffffff;
font-size: 24rpx;
color: #D8FD24;
margin: 200rpx auto 0;
display: flex;
align-items: center;
justify-content: center;
}
</style>

View File

@ -157,6 +157,7 @@
</template>
<script>
import { sleep } from '@/common/util';
export default {
components: {},
data() {
@ -191,19 +192,10 @@ export default {
}
},
onShow() {
this.getdata()
this.getdata();
//
this.menuList = this.$platform.getUserMenuList();
this.zuanshi = this.$platform.code != "MP-WEIXIN";
const curPages = getCurrentPages()[0]; //
// #ifdef MP
if (typeof curPages.getTabBar === 'function' && curPages.getTabBar()) {
this.$mp.page.getTabBar().setData({
selected: 4
});
}
// #endif
},
methods: {
toChange() {
@ -294,7 +286,7 @@ export default {
fail: error => { }
})
},
getlist(index) {
this.show = index
},

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff