feat: 无感登录

This commit is contained in:
mayubo@gmail.com 2025-06-19 18:12:17 +08:00
parent c019e03db8
commit f9ca3cce55
8 changed files with 291 additions and 238 deletions

View File

@ -1,18 +1,23 @@
page {
background: #f6f7fb;
}
.header {
margin: 40rpx 0 45rpx;
display: flex;
flex-direction: column;
align-items: center;
margin: 40rpx 0 45rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.avatar_pic {
width: 130rpx;
height: 130rpx;
border-radius: 50%;
}
.header_desc {
margin-top: 10rpx;
}
.main {
margin: 45rpx 20rpx 62rpx;
background: #FFFFFF;
background: yellow;
background: #ffffff;
border-radius: 20rpx 20rpx 20rpx 20rpx;
}
.tabel {
@ -22,96 +27,49 @@ align-items: center;
}
.left {
font-size: 28rpx;
color: #999999;
margin-right: 68rpx;
color: #999999;
margin-right: 68rpx;
margin-left: 20rpx;
}
.right {
display: flex;
align-items: center;
height: 100rpx;
flex: 1;
border-bottom: 1rpx solid #EBEBEB;
border-bottom: 1rpx solid #ebebeb;
}
.right_radio {
margin-left: 45rpx;
}
.no_border{
border-bottom: none;
}
.btn {
margin: 62rpx 75rpx 60rpx;
height: 90rpx;
line-height: 90rpx;
background: linear-gradient( 91deg, #FF7658 0%, #FF370B 100%);
background: linear-gradient(91deg, #ff7658 0%, #ff370b 100%);
border-radius: 100rpx 100rpx 100rpx 100rpx;
text-align: center;
font-weight: 600;
font-size: 36rpx;
color: #FFFFFF;
color: #ffffff;
}
/* .item{
display:flex;
border-bottom:1px solid #e6e6e6;
height: 90rpx;
.tabel1 {
margin: 0 20rpx;
border-bottom: 1rpx solid #ebebeb;
height: 100rpx;
display: flex;
align-items: center;
justify-content: space-between;
align-items: center;
margin-left: 52rpx;
margin-right: 48rpx;
}
.tabel1 > .right {
flex: 1;
border-bottom: none;
justify-content: flex-end;
}
.item-left {
display: flex;
align-items: center;
.no_border {
border-bottom: none;
}
.item-title {
font-size: 26rpx;
color: #999999;
}
.item-icon {
width: 30rpx;
height: 30rpx;
margin-right: 20rpx;
}
.item-right {
text-align: right;
font-size: 26rpx;
font-weight: 400;
color: #222222;
}
.right-icon {
width: 40rpx;
height: 40rpx;
}
.item-right-icon {
width: 13rpx;
height: 26rpx;
} */
/*
.item:last-child{
border-bottom:none
}
.line {
background: #F9F9F9;
height: 20rpx;
}
.desc {
font-size: 26rpx;
font-weight: 400;
color: #FF512A;
}
.quit_login {
margin: 10rpx 50rpx 0;
background: #FF512A;
border-radius: 100rpx 100rpx 100rpx 100rpx;
height: 80rpx;
color: #FFFFFF;
font-size: 36rpx;
font-weight: 400;
line-height: 80rpx;
} */
.u-upload__wrap__preview {
width: 130rpx;
height: 130rpx;

View File

@ -4,7 +4,7 @@
<u-upload @afterRead="afterReadImg" :deletable="false" :maxCount="1">
<image class="avatar_pic" :src="avatarInfo.url" alt="" />
</u-upload>
<view>点击更换头像</view>
<view class="header_desc">点击更换头像</view>
</view>
<view class="main">
<view class="tabel">
@ -14,7 +14,7 @@
type="text"
placeholder="请填写昵称"
:value="name"
:data-name="name"
data-name="name"
@input="headerInputClick"
/>
</view>
@ -43,22 +43,30 @@
type="text"
placeholder="请填写邮箱地址"
:value="eMail"
:data-name="eMail"
data-name="eMail"
@input="headerInputClick"
/>
</view>
</view>
</view>
<view class="btn">保存设置</view>
<view class="btn" @click="headerSubmitClick">保存设置</view>
<view class="main">
<view class="tabel">
<view class="tabel1" @click="headerRefreshClick">
<view class="left">刷新登录</view>
<view class="right">
<u-icon name="arrow-right" />
</view>
</view>
<button
class="login-btn"
open-type="getPhoneNumber"
style="display: none;"
@click="headerLoginClick"
@getphonenumber="getPhoneNumber"
id="hiddenLoginBtn"
></button>
<view class="tabel no_border" @click="headerSettingClick">
<view class="tabel1 no_border" @click="headerSettingClick">
<view class="left">设置授权</view>
<view class="right">
<u-icon name="arrow-right" />
@ -70,55 +78,24 @@
</template>
<script>
import { NavgateTo, request, picUrl, upload } from "../../../utils/index";
import { request, picUrl, upload, validateEmail } from "../../../utils/index";
import { apiArr } from "../../../api/login";
import { apiArr as apiArr2 } from "../../../api/v2User";
export default {
data() {
return {
avatarInfo: {},
userInfoList: [
{
pic: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/Group_422.png",
desc: "上传头像",
url: "/packages/user/uploadAvatar/index",
isShowPic: true,
},
{
pic: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/Classroom.png",
desc: "当前账户",
url: "",
text: "微信用户",
},
{
pic: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/Group_423.png",
desc: "修改登录密码",
type: "login",
url: "/packages/user/resetPwd/index",
isShowPic: true,
},
{
pic: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/Group_424.png",
desc: "修改支付密码",
type: "pay",
url: "/packages/user/resetPwd/index",
isShowPic: true,
isLast: true,
},
],
name: "",
mobile: "",
eMail: "",
sex: 2,
sex: 0,
};
},
methods: {
//
async afterReadImg(e) {
console.log("eeee", e);
const { file } = e;
upload(file.url, (res) => {
console.log("1111", res);
this.avatarInfo = {
url: picUrl + res.data.path,
picUrl: res.data.path,
@ -129,8 +106,72 @@ export default {
icon: "success",
});
},
headerRefreshClick() {
uni.showLoading({
title: '刷新中',
mask: true
})
//
uni.removeStorageSync('ctoken');
uni.removeStorageSync('userId');
uni.removeStorageSync('openId');
uni.removeStorageSync('phone');
uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop');
uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission');
const button = uni.createSelectorQuery().select('#hiddenLoginBtn');
button.boundingClientRect().exec();
// headerLoginClick
this.headerLoginClick();
},
headerLoginClick() {
let that = this;
uni.login({
onlyAuthorize: true,
success: (res) => {
request(apiArr.login, 'POST', {
code: res.code,
phone: '',
password: '',
}, { silent: false }).then((loginRes) => {
//
uni.setStorageSync('ctoken', loginRes.token);
uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop);
//
request(apiArr.loginInfo, 'POST', {
token: loginRes.token
}, { silent: false } ).then((res2) => {
if (res2.error) return;
// userId 使
uni.setStorageSync('userId', res2.user_id);
uni.setStorageSync('openId', res2.open_id);
uni.setStorageSync('shopId', res2.wshop_id);
that.init(true)
})
}, (err) => {
uni.hideLoading();
console.log('登录接口错误', err);
})
}
})
},
//
getPhoneNumber(event) {
console.log('小程序登录获取手机号', event);
},
headerInputClick(e) {
console.log("ee", e);
const { name } = e.currentTarget.dataset;
const { value } = e.detail;
this[name] = value;
@ -145,12 +186,37 @@ export default {
},
headerRadioClick(item) {
console.log("item", item);
this.sex = item;
},
async init() {
const res = await request(apiArr2.getUserInfo, "POST", {});
console.log("111211", res);
async headerSubmitClick() {
if(this.eMail && !validateEmail(this.eMail)){
uni.showToast({
title: '请输入正确邮箱地址',
icon: 'none'
})
return
};
const res = await request(apiArr2.userInfoUpdate, 'POST', {
gender: this.sex,
avatar: this.avatarInfo.picUrl,
nick_name: this.name,
email: this.eMail,
// mobile
});
uni.showToast({
title: '保存成功',
mask: true
});
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 2000)
},
async init(item = false) {
const res = await request(apiArr2.getUserInfo, "POST", {}, {silent: item === true ? false : true});
this.avatarInfo = {
url: res.avatar
? picUrl + res.avatar
@ -161,6 +227,18 @@ export default {
this.mobile = res.mobile;
this.sex = res.gender;
this.eMail = res.email;
if (item) {
const { community_worker } = res;
uni.setStorageSync('order_dispatch_permission', community_worker && community_worker[0].order_dispatch_permission == 1 || false);
uni.setStorageSync('phone', res.account);
uni.hideLoading();
uni.showToast({
title: '刷新成功',
icon: 'success',
mask: true,
duration: 2000,
})
}
},
},

View File

@ -98,7 +98,6 @@ font-size: 34rpx;
color: #7F3907;
}
.monenyt {
/* display: inline-block; */
margin-left: 17rpx;
margin-right: 37rpx;
font-weight: 400;
@ -157,9 +156,7 @@ margin-right: 20rpx;
flex-direction: column;
align-items: center;
}
.order {
margin-top: 24rpx;
}
.nav_icon {
width: 50rpx;
height: 50rpx;
@ -169,16 +166,7 @@ margin-right: 20rpx;
font-size: 24rpx;
}
.item {
display: flex;
width: 48%;
height: 150rpx;
background-color: #FFFFFF;
border-radius: 30rpx;
justify-content: left;
align-items: center;
/* padding-left: 28rpx; */
}
.item1 {
display: flex;
@ -191,59 +179,24 @@ margin-right: 20rpx;
padding-bottom: 0;
}
.item-owner {
margin:0 116rpx 0 116rpx;
}
.item-icon {
width: 150rpx;
height: 98rpx;
margin-left: 30rpx;
}
.item-icon1 {
width: 150rpx;
height: 120rpx;
margin-left: 30rpx;
.item_device {
display: flex;
flex-direction: column;
align-items: center;
}
.icon-img {
display: flex;
width: 72rpx;
height: 72rpx;
width: 60rpx;
height: 60rpx;
flex-direction: column;
margin-bottom: 28rpx;
margin-left: 17%;
}
.item-content {
display: flex;
flex-direction: column;
padding-left: 28rpx;
margin-bottom: 10rpx;
}
.title-item {
font-size: 26rpx;
}
.item-title {
font-size: 28rpx;
color: #333;
font-weight: bold;
margin-bottom: 5rpx;
}
.item-subtitle {
font-size: 20rpx;
color: #666;
}
.navigation {
margin-top: 29rpx;
margin-left: 22rpx;
font-size: 32rpx;
font-weight: bold;
}
.customer {
width: 130rpx;
height: 130rpx;

View File

@ -8,13 +8,21 @@
</view>
<view class="avatar_right">
<view class="avatar_title">
<view class="login-btn">{{userInfo.user_name ? userInfo.user_name : '登录/注册'}}</view>
<view class="login-btn">{{userInfo.nick_name ? userInfo.nick_name : '登录/注册'}}</view>
<view class="avatar_setting">
<image src="http://127.0.0.1:5500/assets/page_user_Vector13.png" mode="" @click.stop="headerRefreshClick"/>
<button
class="login-btn"
open-type="getPhoneNumber"
style="display: none;"
@click="headerLoginClick"
@getphonenumber="getPhoneNumber"
id="hiddenLoginBtn"
></button>
<image src="http://127.0.0.1:5500/assets/page_user_Vector14.png" mode="" @click.stop="headerSettingsClick"/>
</view>
</view>
<view class="avater_mobile">{{ phoneNum }}</view>
<view class="avater_mobile">{{ userInfo.mobile }}</view>
</view>
</view>
<view class="section section1">
@ -36,23 +44,6 @@
</view>
</view>
<!-- <view class="section">
<view class="item" @click="handlePointsClick">
<view class="item-content">
<text class="item-title">积分</text>
<text class="item-subtitle">我的剩余积分</text>
</view>
<image class="item-icon" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/5bf7d7dca1ff7_1.png">
</image>
</view>
<view class="item" @click="handleSignClick">
<view class="item-content">
<text class="item-title">每日签到</text>
<text class="item-subtitle">签到获取积分</text>
</view>
<image class="item-icon1" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_311.png" />
</view>
</view> -->
<view class="center">
<view class="gold_container">
<view class="gold_title">
@ -65,20 +56,20 @@
<view class="item1">
<view class="item_device" @click="handleCommunityClick">
<image class="icon-community icon-img"
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_16.png"></image>
<text class="community-title title-item">我的社区</text>
src="http://127.0.0.1:5500/assets/page_user_Group_1382.png"></image>
<text class="community-title title-item">我的房产</text>
</view>
<view class="item_device" @click="handleApplyOwnerClick">
<image class="icon-owner icon-img" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Frame.png" />
<text class="owner-title title-item">申请业主</text>
<image class="icon-img" src="http://127.0.0.1:5500/assets/page_user_Group_1559.png" />
<text class="owner-title title-item">物业账单</text>
</view>
<view class="item_device" @click="handleFacilityClick">
<image class="icon-device icon-img" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Frame_1.png"/>
<text class="device-title title-item">我的设备</text>
<image class="icon-img" src="http://127.0.0.1:5500/assets/page_user_Group_1557.png"/>
<text class="device-title title-item">我的工单</text>
</view>
<view class="item_device" @click="handleMeApplyClick">
<image class="icon-device icon-img" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/Group_905.png"/>
<text class="device-title title-item">我的申请</text>
<image class="icon-img" src="http://127.0.0.1:5500/assets/page_user_Group_1558.png"/>
<text class="device-title title-item">我的管家</text>
</view>
</view>
</view>
@ -129,6 +120,7 @@
<script>
import { apiArr } from '../../api/login';
import { apiArr as apiArr2 } from '../../api/v2User';
import { menuButtonInfo, NavgateTo, picUrl, request } from '../../utils/index';
export default {
data() {
@ -197,11 +189,8 @@
url: "",
}
],
userInfo: {},
isShop: false,
phoneNum: uni.getStorageSync('phone'),
}
},
@ -213,12 +202,72 @@
//
headerRefreshClick() {
console.log('刷新')
uni.showLoading({
title: '刷新中',
mask: true
})
//
uni.removeStorageSync('ctoken');
uni.removeStorageSync('userId');
uni.removeStorageSync('openId');
uni.removeStorageSync('phone');
uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop');
uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission');
const button = uni.createSelectorQuery().select('#hiddenLoginBtn');
button.boundingClientRect().exec();
// headerLoginClick
this.headerLoginClick();
},
headerLoginClick() {
let that = this;
uni.login({
onlyAuthorize: true,
success: (res) => {
request(apiArr.login, 'POST', {
code: res.code,
phone: '',
password: '',
}, { silent: false }).then((loginRes) => {
//
uni.setStorageSync('ctoken', loginRes.token);
uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop);
//
request(apiArr.loginInfo, 'POST', {
token: loginRes.token
}, { silent: false } ).then((res2) => {
if (res2.error) return;
// userId 使
uni.setStorageSync('userId', res2.user_id);
uni.setStorageSync('openId', res2.open_id);
uni.setStorageSync('shopId', res2.wshop_id);
that.getUserInfo(true)
})
}, (err) => {
uni.hideLoading();
console.log('登录接口错误', err);
})
}
})
},
//
getPhoneNumber(event) {
console.log('小程序登录获取手机号', event);
},
//
headerSettingsClick() {
console.log('设置')
NavgateTo('/packages/user/index/index');
},
@ -227,16 +276,6 @@
console.log('客服')
},
//
handlePointsClick() {
NavgateTo('/packages/user/points/index');
},
//
handleSignClick() {
NavgateTo('/packages/user/pointsSign/index');
},
//
handleCommunityClick(){
NavgateTo('/packages/community/index/index')
@ -282,22 +321,6 @@
}
},
//
headerGridItemClick(event) {
if (!event.url) {
this.NotOpen();
return
}
//
if (event.url === '/packages/user/customerService/index') {
NavgateTo( event.url, { isLogin: false})
return;
}
if (event.url) {
NavgateTo( event.url)
}
},
//
NotOpen() {
uni.showModal({
@ -314,15 +337,27 @@
},
async getUserInfo() {
async getUserInfo(item = false) {
const isCtoken = uni.getStorageSync('ctoken');
if (!isCtoken) return;
const res = await request(apiArr.loginInfo, 'POST', {});
const res = await request(apiArr2.getUserInfo, 'POST', {}, {silent: item === true ? false : true});
const newUserInfo = {
...res,
userPic: res.img ? `${picUrl}${res.img}` : 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_309.png'
userPic: res.avatar ? `${picUrl}${res.avatar}` : 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_309.png'
};
this.userInfo = newUserInfo;
if (item) {
const { community_worker } = res;
uni.setStorageSync('order_dispatch_permission', community_worker && community_worker[0].order_dispatch_permission == 1 || false);
uni.setStorageSync('phone', res.account);
uni.hideLoading();
uni.showToast({
title: '刷新成功',
icon: 'success',
mask: true,
duration: 2000,
})
}
},
},

File diff suppressed because one or more lines are too long

View File

@ -19342,7 +19342,7 @@ var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/inte
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.uploadVideo = exports.upload = exports.uniqueByField = exports.request = exports.picUrl = exports.menuButtonInfo = exports.isPhone = exports.getProviderPromise = exports.floatCalculate = exports.calculateDistance = exports.NavgateTo = void 0;
exports.validateEmail = exports.uploadVideo = exports.upload = exports.uniqueByField = exports.request = exports.picUrl = exports.menuButtonInfo = exports.isPhone = exports.getProviderPromise = exports.floatCalculate = exports.calculateDistance = exports.NavgateTo = void 0;
var _defineProperty2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/defineProperty */ 11));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@ -19713,7 +19713,18 @@ var uniqueByField = function uniqueByField(arr, field) {
return seen.hasOwnProperty(key) ? false : seen[key] = true;
});
};
// 校验邮箱地址是否合法
exports.uniqueByField = uniqueByField;
var validateEmail = function validateEmail(email) {
// 正则表达式验证邮箱格式
var regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!regex.test(email)) {
return false;
}
return true;
};
exports.validateEmail = validateEmail;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))
/***/ }),

View File

@ -3,12 +3,19 @@
"miniprogram": {
"list": [
{
"name": "个人设置",
"pathName": "packages/user/index/index",
"name": "pages/user/index",
"pathName": "pages/user/index",
"query": "",
"scene": null,
"launchMode": "default"
},
{
"name": "个人设置",
"pathName": "packages/user/index/index",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "完善注册信息",
"pathName": "packages/user/replenishInfo/index",

View File

@ -358,4 +358,15 @@ export const uniqueByField = (arr, field) => {
});
}
// 校验邮箱地址是否合法
export const validateEmail = (email) => {
// 正则表达式验证邮箱格式
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!regex.test(email)) {
return false;
}
return true
}