This commit is contained in:
commie
2025-11-23 01:01:52 +08:00
parent 6ec389ff41
commit 0783e46b4b
21 changed files with 6409 additions and 1264 deletions
+1
View File
@@ -76,6 +76,7 @@
"updateSentGroupApplition",
]),
setGlobalIMlistener() {
this.$store.dispatch("system/getConfig");
console.log("setGlobalIMlistener");
// init
const kickHander = (message) => {
+11 -9
View File
@@ -1,18 +1,20 @@
// 登录
export const businessConfig = (params) =>
uni.$u?.http.post("/common/init", JSON.stringify(params));
export const businessLogin = (params) =>
uni.$u?.http.post("/account/login", JSON.stringify(params));
uni.$u?.http.post("/common/login", JSON.stringify(params));
export const businessSendSms = (params) =>
uni.$u?.http.post("/account/code/send", JSON.stringify(params));
uni.$u?.http.post("/common/captcha", JSON.stringify(params));
export const businessVerifyCode = (params) =>
uni.$u?.http.post("/account/code/verify", JSON.stringify(params));
uni.$u?.http.post("/common/verify_captcha", JSON.stringify(params));
export const businessRegister = (params) =>
uni.$u?.http.post("/account/register", JSON.stringify(params));
uni.$u?.http.post("/common/register", JSON.stringify(params));
export const businessReset = (params) =>
uni.$u?.http.post("/account/password/reset", JSON.stringify(params));
uni.$u?.http.post("/common/resetpwd", JSON.stringify(params));
export const businessModify = (params) =>
uni.$u?.http.post(
"/account/password/change",
"/user/change_password",
JSON.stringify({
...params,
}), {
@@ -25,7 +27,7 @@ export const businessModify = (params) =>
// 用户信息
export const businessInfoUpdate = (params) =>
uni.$u?.http.post(
"/user/update",
"/user/profile",
JSON.stringify({
...params,
}), {
@@ -36,7 +38,7 @@ export const businessInfoUpdate = (params) =>
);
export const businessGetUserInfo = (userID) =>
uni.$u?.http.post(
"/user/find/full",
"/user/find",
JSON.stringify({
userIDs: [userID],
}), {
@@ -48,7 +50,7 @@ export const businessGetUserInfo = (userID) =>
export const businessSearchUserInfo = (keyword) =>
uni.$u?.http.post(
"/user/search/full",
"/user/search",
JSON.stringify({
keyword,
pagination: {
+9 -9
View File
@@ -3,23 +3,23 @@
// const API_URL = `http://${BASE_HOST}:10002`
// const WS_URL = `ws://${BASE_HOST}:10001`
const BASE_DOMAIN = '156.238.245.175'
const BASE_DOMAIN = 'www.axzc.xyz'
// const CHAT_URL = `https://${BASE_DOMAIN}/chat`
// const API_URL = `https://${BASE_DOMAIN}/api`
// const WS_URL = `wss://${BASE_DOMAIN}/msg_gateway`
const CHAT_URL = `http://${BASE_DOMAIN}:10008`
const API_URL = `http://${BASE_DOMAIN}:10002`
const WS_URL = `ws://${BASE_DOMAIN}:10001`
const CHAT_URL = `http://${BASE_DOMAIN}:8585/api`
const API_URL = `http://${BASE_DOMAIN}/imapi`
const WS_URL = `ws://${BASE_DOMAIN}/ws`
const version = 'Uniapp-Demo'
const version = '2.0.6'
const getRegisterUrl = () => uni.getStorageSync("IMRegisteUrl") || CHAT_URL;
const getApiUrl = () => uni.getStorageSync("IMApiUrl") || API_URL;
const getWsUrl = () => uni.getStorageSync("IMWsUrl") || WS_URL;
module.exports = {
version,
getRegisterUrl,
getApiUrl,
getWsUrl,
version,
getRegisterUrl,
getApiUrl,
getWsUrl,
};
Generated
+4959
View File
File diff suppressed because it is too large Load Diff
+378 -403
View File
@@ -1,439 +1,414 @@
<template>
<view class="page_container">
<view class="login">
<view class="logo">
<img src="static/images/logo.png" alt="" />
<view class="title">欢迎使用OpenCorp</view>
</view>
<u-tabs :list="list" @click="click"></u-tabs>
<u-form
class="loginForm"
labelPosition="top"
:model="loginInfo"
:labelStyle="{
<view class="page_container">
<view class="login">
<view class="logo">
<img src="static/images/logo.png" alt="" />
<view class="title">欢迎使用{{config.name}}</view>
</view>
<u-tabs :list="list" :current="active" @click="click"></u-tabs>
<u-form class="loginForm" labelPosition="top" :model="loginInfo" :labelStyle="{
fontSize: '14px',
marginTop: '20rpx',
width: 'max-content',
}"
ref="loginForm"
>
<u-form-item v-if="active === 0" label="" prop="phoneNumber">
<u-input
v-model="loginInfo.phoneNumber"
border="surround"
placeholder="请输入手机号码"
clearable
>
<view
slot="prefix"
class="phoneNumber_areacode"
@click="showPicker"
>
<text class="areacode_content">+{{ loginInfo.areaCode }}</text>
<u-icon class="arrow_down" name="arrow-down"></u-icon>
</view>
</u-input>
</u-form-item>
<u-form-item v-if="active === 1" label="" prop="email">
<u-input
v-model="loginInfo.email"
border="surround"
placeholder="请输入您的邮箱"
clearable
>
</u-input>
</u-form-item>
<u-form-item v-if="active > 1 || isPwdLogin" label="" prop="password">
<u-input
v-model="loginInfo.password"
border="surround"
placeholder="请输入密码"
:password="!eying"
clearable
>
<u-icon
@click="updateEye"
slot="suffix"
:name="eying ? 'eye-off' : 'eye'"
>
</u-icon>
</u-input>
</u-form-item>
<u-form-item
v-if="active <= 1 && !isPwdLogin"
label=""
prop="verificationCode"
>
<u-input
v-model="loginInfo.verificationCode"
border="surround"
placeholder="请输入验证码"
>
<view class="code_btn" slot="suffix" @click="getCode">
{{ count !== 0 ? `${count} s` : "获取验证码" }}
</view>
</u-input>
</u-form-item>
</u-form>
<view v-if="active <= 1" class="other">
<text @click="toRegisterOrForget(false)">忘记密码</text>
<text class="forget" @click="toggleLoginMethod">{{ isPwdLogin ? "验证码登录" : "密码登录" }}</text>
</view>
<view class="login-btn">
<u-button
:loading="loading"
type="primary"
@click="startLogin"
:disabled="!canLogin"
>
登录
</u-button>
</view>
}" ref="loginForm">
<u-form-item v-if="active === 0" label="" prop="phoneNumber">
<u-input v-model="loginInfo.phoneNumber" border="surround" placeholder="请输入手机号码" clearable>
<view slot="prefix" class="phoneNumber_areacode" @click="showPicker">
<text class="areacode_content">+{{ loginInfo.areaCode }}</text>
<u-icon class="arrow_down" name="arrow-down"></u-icon>
</view>
</u-input>
</u-form-item>
<u-form-item v-if="active === 1" label="" prop="email">
<u-input v-model="loginInfo.email" border="surround" placeholder="请输入您的邮箱" clearable>
</u-input>
</u-form-item>
<u-form-item v-if="active > 1 || isPwdLogin" label="" prop="password">
<u-input v-model="loginInfo.password" border="surround" placeholder="请输入密码" :password="!eying"
clearable>
<u-icon @click="updateEye" slot="suffix" :name="eying ? 'eye-off' : 'eye'">
</u-icon>
</u-input>
</u-form-item>
<u-form-item v-if="active <= 1 && !isPwdLogin" label="" prop="verificationCode">
<u-input v-model="loginInfo.verificationCode" border="surround" placeholder="请输入验证码">
<view class="code_btn" slot="suffix" @click="getCode">
{{ count !== 0 ? `${count} s` : "获取验证码" }}
</view>
</u-input>
</u-form-item>
</u-form>
<view v-if="active <= 1" class="other">
<text @click="toRegisterOrForget(false)">忘记密码</text>
<text class="forget" @click="toggleLoginMethod">{{ isPwdLogin ? "验证码登录" : "密码登录" }}</text>
</view>
<view class="login-btn">
<u-button :loading="loading" type="primary" @click="startLogin" :disabled="!canLogin">
登录
</u-button>
</view>
<AreaPicker ref="AreaPicker" @chooseArea="chooseArea" />
</view>
<AreaPicker ref="AreaPicker" @chooseArea="chooseArea" />
</view>
<view class="action_bar">
<text>还没有账号<text class="register" @click="toRegisterOrForget(true)">立即注册</text></text>
<text style="margin-bottom: 16rpx" @click="copy">{{ v }}</text>
</view>
</view>
<view class="action_bar">
<text>还没有账号<text class="register" @click="toRegisterOrForget(true)">立即注册</text></text>
<text style="margin-bottom: 16rpx" @click="copy">{{ v }}</text>
</view>
</view>
</template>
<script>
import { v4 as uuidv4 } from "uuid";
import md5 from "md5";
import { version } from '@/common/config'
import { businessLogin, businessSendSms } from "@/api/login";
import AreaPicker from "@/components/AreaPicker";
import { checkLoginError } from "@/util/common";
import { SmsUserFor } from "@/constant";
import IMSDK from "openim-uniapp-polyfill";
import { mapGetters } from "vuex";
import { v4 as uuidv4 } from "uuid";
import md5 from "md5";
import { version } from '@/common/config'
import { businessLogin, businessSendSms } from "@/api/login";
import AreaPicker from "@/components/AreaPicker";
import { checkLoginError } from "@/util/common";
import { SmsUserFor } from "@/constant";
import IMSDK from "openim-uniapp-polyfill";
let timer;
let timer;
export default {
components: {
AreaPicker,
},
data() {
return {
list: [{
name: '手机号',
}, {
name: '邮箱',
}],
loginInfo: {
email: "",
phoneNumber: "",
password: "",
areaCode: "86",
verificationCode: "",
},
eying: false,
loading: false,
count: 0,
isPwdLogin: true,
active: 0,
};
},
computed: {
v() {
return version
},
canLogin() {
return (
(this.loginInfo.phoneNumber || this.loginInfo.email) &&
(this.loginInfo.password || this.loginInfo.verificationCode)
);
},
},
onLoad(options) {
// if(options.isRedirect){
// plus.navigator.closeSplashscreen();
// }
this.version = version
this.init();
},
methods: {
click({ index }) {
this.active = index;
},
copy() {
uni.setClipboardData({
showToast: false,
data: version,
success: function () {
uni.showToast({
icon: "none",
title: "复制成功",
});
},
});
},
init() {
this.loginInfo.areaCode = uni.getStorageSync("last_areaCode") || "86";
this.loginInfo.email = uni.getStorageSync("last_email") || "";
this.loginInfo.phoneNumber = uni.getStorageSync("last_phoneNumber") || "";
},
updateEye() {
this.eying = !this.eying;
},
toRegisterOrForget(isRegister) {
uni.$u.route("/pages/login/registerOrForget/index", {
isRegister,
});
},
async startLogin() {
// this.$refs.loginForm.validate().then(async (valid) => {
this.loading = true;
this.saveLoginInfo();
let data = {};
try {
data = await businessLogin({
phoneNumber: this.loginInfo.phoneNumber,
email: this.loginInfo.email,
areaCode: `+${this.loginInfo.areaCode}`,
password: this.isPwdLogin ? md5(this.loginInfo.password) : "",
platform: uni.$u.os() === "ios" ? 1 : 2,
verifyCode: this.loginInfo.verificationCode,
});
const { imToken, userID } = data;
await IMSDK.asyncApi(IMSDK.IMMethods.Login, uuidv4(), {
userID,
token: imToken,
});
this.saveLoginProfile(data);
this.$store.commit("user/SET_AUTH_DATA", data);
this.$store.dispatch("user/getSelfInfo");
this.$store.dispatch("conversation/getConversationList");
this.$store.dispatch("conversation/getUnReadCount");
// this.$store.dispatch("contact/getFriendList");
// this.$store.dispatch("contact/getGrouplist");
this.$store.dispatch("contact/getBlacklist");
this.$store.dispatch("contact/getRecvFriendApplications");
this.$store.dispatch("contact/getSentFriendApplications");
this.$store.dispatch("contact/getRecvGroupApplications");
this.$store.dispatch("contact/getSentGroupApplications");
uni.switchTab({
url: "/pages/conversation/conversationList/index",
});
this.loginInfo.password = "";
} catch (err) {
console.error(err);
uni.$u.toast(checkLoginError(err));
}
this.loading = false;
// });
},
saveLoginProfile(data) {
const { imToken, chatToken, userID } = data;
uni.setStorage({
key: "IMUserID",
data: userID,
});
uni.setStorage({
key: "IMToken",
data: imToken,
});
uni.setStorage({
key: "BusinessToken",
data: chatToken,
});
},
saveLoginInfo() {
uni.setStorage({
key: "last_areaCode",
data: this.loginInfo.areaCode,
});
uni.setStorage({
key: "last_phoneNumber",
data: this.loginInfo.phoneNumber,
});
uni.setStorage({
key: "last_email",
data: this.loginInfo.email,
});
},
showPicker() {
this.$refs.AreaPicker.init();
},
chooseArea(areaCode) {
this.loginInfo.areaCode = areaCode;
},
toggleLoginMethod() {
this.isPwdLogin = !this.isPwdLogin;
},
getCode() {
if (!this.loginInfo.phoneNumber) {
uni.$u.toast("请先输入手机号!");
return;
}
export default {
components: {
AreaPicker,
},
data() {
return {
list: [{
name: '手机号',
}, {
name: '邮箱',
}],
loginInfo: {
email: "",
phoneNumber: "",
password: "",
areaCode: "86",
verificationCode: "",
},
eying: false,
loading: false,
count: 0,
isPwdLogin: true,
active: 1,
};
},
computed: {
...mapGetters([
"config",
]),
v() {
return this.config.name+' '+version
},
canLogin() {
return (
(this.loginInfo.phoneNumber || this.loginInfo.email) &&
(this.loginInfo.password || this.loginInfo.verificationCode)
);
},
},
onLoad(options) {
// if(options.isRedirect){
// plus.navigator.closeSplashscreen();
// }
this.version = version
this.init();
},
methods: {
click({
index
}) {
this.active = index;
},
copy() {
uni.setClipboardData({
showToast: false,
data: version,
success: function() {
uni.showToast({
icon: "none",
title: "复制成功",
});
},
});
},
init() {
this.loginInfo.areaCode = uni.getStorageSync("last_areaCode") || "86";
this.loginInfo.email = uni.getStorageSync("last_email") || "";
this.loginInfo.phoneNumber = uni.getStorageSync("last_phoneNumber") || "";
if (this.count !== 0) {
return;
}
if(process.env.NODE_ENV == 'development'){
this.loginInfo.email = "commiu@outlook.com";
this.loginInfo.password = "qwe123";
}
},
updateEye() {
this.eying = !this.eying;
},
toRegisterOrForget(isRegister) {
uni.$u.route("/pages/login/registerOrForget/index", {
isRegister,
});
},
async startLogin() {
// this.$refs.loginForm.validate().then(async (valid) => {
this.loading = true;
this.saveLoginInfo();
let data = {};
try {
data = await businessLogin({
mobile: this.loginInfo.phoneNumber,
email: this.loginInfo.email,
areaCode: `+${this.loginInfo.areaCode}`,
password: this.isPwdLogin ? md5(this.loginInfo.password) : "",
platform: uni.$u.os() === "ios" ? 1 : 2,
type: this.active === 0 ? 'mobile' : 'email',
code: this.loginInfo.verificationCode,
});
const {
imToken,
userID
} = data;
await IMSDK.asyncApi(IMSDK.IMMethods.Login, uuidv4(), {
userID,
token: imToken,
});
this.saveLoginProfile(data);
this.$store.commit("user/SET_AUTH_DATA", data);
this.$store.dispatch("user/getSelfInfo");
this.$store.dispatch("conversation/getConversationList");
this.$store.dispatch("conversation/getUnReadCount");
// this.$store.dispatch("contact/getFriendList");
// this.$store.dispatch("contact/getGrouplist");
this.$store.dispatch("contact/getBlacklist");
this.$store.dispatch("contact/getRecvFriendApplications");
this.$store.dispatch("contact/getSentFriendApplications");
this.$store.dispatch("contact/getRecvGroupApplications");
this.$store.dispatch("contact/getSentGroupApplications");
uni.switchTab({
url: "/pages/conversation/conversationList/index",
});
this.loginInfo.password = "";
} catch (err) {
console.error(err);
uni.$u.toast(checkLoginError(err));
}
this.loading = false;
// });
},
saveLoginProfile(data) {
const {
imToken,
token,
userID
} = data;
uni.setStorage({
key: "IMUserID",
data: userID,
});
uni.setStorage({
key: "IMToken",
data: imToken,
});
uni.setStorage({
key: "BusinessToken",
data: token,
});
},
saveLoginInfo() {
uni.setStorage({
key: "last_areaCode",
data: this.loginInfo.areaCode,
});
uni.setStorage({
key: "last_phoneNumber",
data: this.loginInfo.phoneNumber,
});
uni.setStorage({
key: "last_email",
data: this.loginInfo.email,
});
},
showPicker() {
this.$refs.AreaPicker.init();
},
chooseArea(areaCode) {
this.loginInfo.areaCode = areaCode;
},
toggleLoginMethod() {
this.isPwdLogin = !this.isPwdLogin;
},
getCode() {
if (!this.loginInfo.phoneNumber) {
uni.$u.toast("请先输入手机号!");
return;
}
const options = {
phoneNumber: this.loginInfo.phoneNumber,
areaCode: `+${this.loginInfo.areaCode}`,
usedFor: SmsUserFor.Login,
operationID: Date.now() + "",
};
businessSendSms(options)
.then(() => {
uni.$u.toast("验证码已发送!");
this.startCount();
})
.catch((err) => {
console.error(err);
uni.$u.toast(checkLoginError(err));
});
},
startCount() {
if (timer) {
clearInterval(timer);
}
this.count = 60;
timer = setInterval(() => {
if (this.count > 0) {
this.count--;
}
}, 1000);
},
},
};
if (this.count !== 0) {
return;
}
const options = {
phoneNumber: this.loginInfo.phoneNumber,
areaCode: `+${this.loginInfo.areaCode}`,
usedFor: SmsUserFor.Login,
operationID: Date.now() + "",
};
businessSendSms(options)
.then(() => {
uni.$u.toast("验证码已发送!");
this.startCount();
})
.catch((err) => {
console.error(err);
uni.$u.toast(checkLoginError(err));
});
},
startCount() {
if (timer) {
clearInterval(timer);
}
this.count = 60;
timer = setInterval(() => {
if (this.count > 0) {
this.count--;
}
}, 1000);
},
},
};
</script>
<style lang="scss" scoped>
.page_container {
justify-content: space-between;
.page_container {
justify-content: space-between;
.login {
color: #0c1c33;
padding: 10vh 80rpx 0;
background: linear-gradient(
180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%
);
.login {
color: #0c1c33;
padding: 10vh 80rpx 0;
background: linear-gradient(180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%);
.title {
font-size: 34rpx;
font-weight: 700;
margin-bottom: 64rpx;
// color: $u-primary;
}
.title {
font-size: 34rpx;
font-weight: 700;
margin-bottom: 64rpx;
// color: $u-primary;
}
.logo {
display: flex;
flex-direction: column;
justify-content: start;
align-items: start;
.logo {
display: flex;
flex-direction: column;
justify-content: start;
align-items: start;
img {
width: 160rpx;
height: 160rpx;
}
}
img {
width: 160rpx;
height: 160rpx;
}
}
.loginType {
margin-bottom: 36rpx;
.loginType {
margin-bottom: 36rpx;
&-item {
margin-right: 68rpx;
font-size: 28rpx;
font-weight: 400;
border-radius: 4rpx;
padding: 2rpx 0;
}
&-item {
margin-right: 68rpx;
font-size: 28rpx;
font-weight: 400;
border-radius: 4rpx;
padding: 2rpx 0;
}
&-active {
color: $u-primary;
border-bottom: 4rpx solid $u-primary;
}
}
&-active {
color: $u-primary;
border-bottom: 4rpx solid $u-primary;
}
}
.loginForm {
.phoneNumber-code {
display: flex;
align-items: center;
font-size: 36rpx;
border-right: 2rpx solid #d8d8d8;
margin-right: 58rpx;
.loginForm {
.phoneNumber-code {
display: flex;
align-items: center;
font-size: 36rpx;
border-right: 2rpx solid #d8d8d8;
margin-right: 58rpx;
.code {
font-weight: 400;
margin-right: 20rpx;
}
.code {
font-weight: 400;
margin-right: 20rpx;
}
.icon {
margin-right: 40rpx;
}
}
.icon {
margin-right: 40rpx;
}
}
.eye {
.image {
width: 44rpx;
height: 32rpx;
}
}
.eye {
.image {
width: 44rpx;
height: 32rpx;
}
}
.code_btn {
color: $u-primary;
}
}
.code_btn {
color: $u-primary;
}
}
.other {
display: flex;
flex-direction: row;
justify-content: space-between;
margin: 8rpx;
font-size: 24rpx;
font-weight: 400;
color: $u-tips-color;
.other {
display: flex;
flex-direction: row;
justify-content: space-between;
margin: 8rpx;
font-size: 24rpx;
font-weight: 400;
color: $u-tips-color;
.forget {
color: $u-primary;
}
}
.forget {
color: $u-primary;
}
}
.login-btn {
margin-top: 8vh;
}
.login-btn {
margin-top: 8vh;
}
.agreement {
display: flex;
align-items: flex-start;
margin-top: 36rpx;
.agreement {
display: flex;
align-items: flex-start;
margin-top: 36rpx;
.detail {
font-size: 24rpx;
font-weight: 400;
color: $u-primary;
}
}
}
.detail {
font-size: 24rpx;
font-weight: 400;
color: $u-primary;
}
}
}
.action_bar {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
margin-bottom: 96rpx;
font-size: 24rpx;
font-weight: 400;
color: $u-tips-color;
.action_bar {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
margin-bottom: 96rpx;
font-size: 24rpx;
font-weight: 400;
color: $u-tips-color;
.register {
color: $u-primary;
}
.register {
color: $u-primary;
}
.tap_line {
width: 1px;
margin: 0 24rpx;
background-color: #999;
transform: scale(0.5, 0.8);
}
}
}
.tap_line {
width: 1px;
margin: 0 24rpx;
background-color: #999;
transform: scale(0.5, 0.8);
}
}
}
</style>
+19 -3
View File
@@ -10,7 +10,11 @@
marginTop: '20rpx',
minWidth: '200rpx',
}" ref="registerForm">
<u-form-item prop="phoneNumber" label="手机号码">
<u-form-item prop="email" label="邮箱" v-if="userInfo.type == 'email'">
<u-input v-model="userInfo.email" border="surround" placeholder="请输入邮箱" clearable>
</u-input>
</u-form-item>
<u-form-item prop="phoneNumber" label="手机号码" v-if="userInfo.type == 'mobile'">
<u-input v-model="userInfo.phoneNumber" border="surround" placeholder="请输入手机号码" clearable>
<view slot="prefix" class="phoneNumber_areacode" @click="showPicker">
<text class="areacode_content">+{{ userInfo.areaCode }}</text>
@@ -50,6 +54,7 @@
email: "",
areaCode: "86",
invitationCode: "",
type:'email',
},
checked: [true],
rules: {
@@ -60,6 +65,12 @@
trigger: ["blur", "change"],
pattern: /^\d{11}$/,
}, ],
email: [{
type: "email",
required: true,
message: "请输入邮箱",
trigger: ["blur", "change"]
}, ],
},
isRegister: true,
pageStatus: "normal",
@@ -67,15 +78,20 @@
},
onLoad(param) {
this.isRegister = JSON.parse(param.isRegister);
if(process.env.NODE_ENV == 'development'){
this.userInfo.email = "commiu@outlook.com";
}
},
methods: {
sendSms() {
this.$refs.registerForm.validate().then((valid) => {
const options = {
phoneNumber: this.userInfo.phoneNumber,
mobile: this.userInfo.mobile,
email: this.userInfo.email,
areaCode: `+${this.userInfo.areaCode}`,
usedFor: this.isRegister ? SmsUserFor.Register : SmsUserFor.Reset,
event: this.isRegister ? 'register' : "reset_pwd",
invitationCode: this.userInfo.invitationCode,
type:this.userInfo.type
};
businessSendSms(options)
.then(() => {
+143 -161
View File
@@ -1,174 +1,156 @@
<template>
<view class="set_password_container content_with_back">
<view class="title">重置密码</view>
<u-form
class="loginForm commonPage-form"
labelPosition="top"
:model="formData"
:rules="rules"
:labelStyle="{
<view class="set_password_container content_with_back">
<view class="title">重置密码</view>
<u-form class="loginForm commonPage-form" labelPosition="top" :model="formData" :rules="rules" :labelStyle="{
fontSize: '14px',
marginTop: '20rpx',
minWidth: '200rpx',
}"
ref="loginForm"
>
<u-form-item label="密码" prop="password">
<u-input
v-model="formData.password"
border="surround"
placeholder="请输入密码"
:password="!passwordEying"
>
<u-icon
@click="updateEye('passwordEying')"
slot="suffix"
:name="passwordEying ? 'eye-off' : 'eye'"
></u-icon>
</u-input>
</u-form-item>
<view class="feild_desc">620至少包含数字字母</view>
<u-form-item label="确认密码" prop="confirmPassword">
<u-input
v-model="formData.confirmPassword"
border="surround"
placeholder="请输入密码"
:password="!comfirmEying"
>
<u-icon
@click="updateEye('comfirmEying')"
slot="suffix"
:name="comfirmEying ? 'eye-off' : 'eye'"
></u-icon>
</u-input>
</u-form-item>
</u-form>
<view class="action_btn">
<u-button type="primary" @click="doNext">
确认修改
</u-button>
</view>
</view>
}" ref="loginForm">
<u-form-item label="密码" prop="password">
<u-input v-model="formData.password" border="surround" placeholder="请输入密码" :password="!passwordEying">
<u-icon @click="updateEye('passwordEying')" slot="suffix"
:name="passwordEying ? 'eye-off' : 'eye'"></u-icon>
</u-input>
</u-form-item>
<view class="feild_desc">620至少包含数字字母</view>
<u-form-item label="确认密码" prop="confirmPassword">
<u-input v-model="formData.confirmPassword" border="surround" placeholder="请输入密码"
:password="!comfirmEying">
<u-icon @click="updateEye('comfirmEying')" slot="suffix"
:name="comfirmEying ? 'eye-off' : 'eye'"></u-icon>
</u-input>
</u-form-item>
</u-form>
<view class="action_btn">
<u-button type="primary" @click="doNext">
确认修改
</u-button>
</view>
</view>
</template>
<script>
import { businessReset } from "@/api/login";
export default {
data() {
return {
isRegister: false,
codeValue: "",
userInfo: {
phoneNumber: "",
areaCode: "",
},
formData: {
password: "",
confirmPassword: "",
},
passwordEying: false,
comfirmEying: false,
rules: {
password: [
{
type: "string",
required: true,
message: "请输入密码",
trigger: ["blur", "change"],
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/,
},
{
validator: (rule, value, callback) => {
return value.length >= 6;
},
message: "密码太短",
trigger: ["change", "blur"],
},
],
confirmPassword: [
{
type: "string",
required: true,
message: "请输入确认密码",
trigger: ["blur", "change"],
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/,
},
{
validator: (rule, value, callback) => {
return value === this.formData.password;
},
message: "两次密码不一致",
trigger: ["change", "blur"],
},
],
},
};
},
onLoad(options) {
const { userInfo, isRegister, codeValue } = options;
this.userInfo = JSON.parse(userInfo);
this.isRegister = JSON.parse(isRegister);
this.codeValue = codeValue;
},
onBackPress() {
return true;
},
methods: {
doNext() {
this.$refs.loginForm.validate().then((valid) => {
if (valid) {
const options = {
phoneNumber: this.userInfo.phoneNumber,
areaCode: `+${this.userInfo.areaCode}`,
VerifyCode: this.codeValue,
password: this.formData.password,
platform: uni.$u.os() === "ios" ? 1 : 2,
operationID: Date.now() + "",
};
businessReset(options)
.then(() => {
uni.$u.toast("密码重置成功,请前往登录!");
setTimeout(() => uni.$u.route("/pages/login/index"), 1000);
})
.catch((err) => {
console.log('err', err)
uni.$u.toast("密码重置失败")
});
}
});
},
updateEye(key) {
this[key] = !this[key];
},
},
};
import {
businessReset
} from "@/api/login";
export default {
data() {
return {
isRegister: false,
codeValue: "",
userInfo: {
phoneNumber: "",
email:"",
areaCode: "",
},
formData: {
password: "",
confirmPassword: "",
},
passwordEying: false,
comfirmEying: false,
rules: {
password: [{
type: "string",
required: true,
message: "请输入密码",
trigger: ["blur", "change"],
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/,
},
{
validator: (rule, value, callback) => {
return value.length >= 6;
},
message: "密码太短",
trigger: ["change", "blur"],
},
],
confirmPassword: [{
type: "string",
required: true,
message: "请输入确认密码",
trigger: ["blur", "change"],
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/,
},
{
validator: (rule, value, callback) => {
return value === this.formData.password;
},
message: "两次密码不一致",
trigger: ["change", "blur"],
},
],
},
};
},
onLoad(options) {
const {
userInfo,
isRegister,
codeValue
} = options;
this.userInfo = JSON.parse(userInfo);
this.isRegister = JSON.parse(isRegister);
this.codeValue = codeValue;
},
onBackPress() {
return true;
},
methods: {
doNext() {
this.$refs.loginForm.validate().then((valid) => {
if (valid) {
const options = {
mobile: this.userInfo.phoneNumber,
email: this.userInfo.em,
areaCode: `+${this.userInfo.areaCode}`,
code: this.codeValue,
password: this.formData.password,
platform: uni.$u.os() === "ios" ? 1 : 2,
operationID: Date.now() + "",
};
businessReset(options)
.then(() => {
uni.$u.toast("密码重置成功,请前往登录!");
setTimeout(() => uni.$u.route("/pages/login/index"), 1000);
})
.catch((err) => {
console.log('err', err)
uni.$u.toast("密码重置失败")
});
}
});
},
updateEye(key) {
this[key] = !this[key];
},
},
};
</script>
<style lang="scss" scoped>
.set_password_container {
margin-top: var(--status-bar-height);
background: linear-gradient(
180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%
);
padding-top: 150rpx;
.set_password_container {
margin-top: var(--status-bar-height);
background: linear-gradient(180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%);
padding-top: 150rpx;
.title {
font-size: 34rpx;
font-weight: 600;
margin-bottom: 116rpx;
padding-bottom: 8rpx;
color: $u-primary;
}
.title {
font-size: 34rpx;
font-weight: 600;
margin-bottom: 116rpx;
padding-bottom: 8rpx;
color: $u-primary;
}
.feild_desc {
font-size: 24rpx;
color: $u-tips-color;
margin-top: 4rpx;
}
.feild_desc {
font-size: 24rpx;
color: $u-tips-color;
margin-top: 4rpx;
}
.action_btn {
margin-top: 12vh;
}
}
.action_btn {
margin-top: 12vh;
}
}
</style>
+22 -9
View File
@@ -54,6 +54,7 @@
codeValue: "",
userInfo: {
phoneNumber: "",
email: "",
areaCode: "",
nickname: "",
password: "",
@@ -71,7 +72,7 @@
required: true,
message: "请输入密码",
trigger: ["blur", "change"],
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/,
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{6,}$/,
},
{
validator: (rule, value, callback) => {
@@ -86,7 +87,7 @@
required: true,
message: "请输入确认密码",
trigger: ["blur", "change"],
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/,
pattern: /^(?=.*\d)(?=.*[a-zA-Z]).{6,}$/,
},
{
validator: (rule, value, callback) => {
@@ -109,6 +110,12 @@
...JSON.parse(userInfo),
};
this.codeValue = codeValue;
if(process.env.NODE_ENV == 'development'){
this.userInfo.email = "commiu@outlook.com";
this.userInfo.nickname = "commiu";
this.userInfo.password = "qwe123";
this.userInfo.confirmPassword = "qwe123";
}
},
onBackPress() {
return true;
@@ -127,14 +134,13 @@
async doRegister() {
this.loading = true;
const options = {
verifyCode: this.codeValue,
code: this.codeValue,
platform: uni.$u.os() === "ios" ? 1 : 2,
autoLogin: true,
user: {
...this.userInfo,
areaCode: `+${this.userInfo.areaCode}`,
password: md5(this.userInfo.password),
},
...this.userInfo,
areaCode: `+${this.userInfo.areaCode}`,
password: md5(this.userInfo.password),
mobile: `+${this.userInfo.phoneNumber}`,
};
try {
await businessRegister(options);
@@ -143,7 +149,14 @@
uni.$u.route("/pages/login/index")
} catch (err) {
console.log(err);
uni.$u.toast(checkLoginError(err));
if(err.msg=="验证码过期" || err.msg=="验证码错误"){
uni.$u.route("/pages/login/verifyCode/index", {
userInfo: JSON.stringify(this.userInfo),
isRegister: true,
resend: 1,
})
return ;
}
// uni.$u.toast('注册失败')
} finally {
this.loading = false;
+23 -8
View File
@@ -22,7 +22,8 @@
</view>
</template>
<script>
import {
import user from "../../../store/modules/user";
import {
businessSendSms,
businessVerifyCode
} from "@/api/login";
@@ -41,6 +42,9 @@
userInfo: {
phoneNumber: "",
areaCode: "",
email: "",
code: "",
type: "email",
},
isRegister: false,
};
@@ -48,11 +52,18 @@
onLoad(options) {
const {
userInfo,
isRegister
isRegister,
resend
} = options;
console.log(userInfo,isRegister)
this.userInfo = JSON.parse(userInfo);
this.isRegister = JSON.parse(isRegister);
this.startCount();
if(resend == 1){
this.count = 0;
this.getSmsAgain();
}else{
this.startCount();
}
},
onReady() {},
methods: {
@@ -63,10 +74,12 @@
},
checkCode(value) {
const options = {
phoneNumber: this.userInfo.phoneNumber,
mobile: this.userInfo.phoneNumber,
email: this.userInfo.email,
type: this.userInfo.type,
areaCode: `+${this.userInfo.areaCode}`,
usedFor: this.isRegister ? SmsUserFor.Register : SmsUserFor.Reset,
verifyCode: value,
event: this.isRegister ? 'register' : 'reset_pwd',
code: value,
};
businessVerifyCode(options)
.then(() => {
@@ -102,9 +115,11 @@
getSmsAgain() {
if (this.count === 0) {
const options = {
phoneNumber: this.userInfo.phoneNumber,
mobile: this.userInfo.phoneNumber,
email: this.userInfo.email,
type: this.userInfo.type,
areaCode: `+${this.userInfo.areaCode}`,
usedFor: this.isRegister ? SmsUserFor.Register : SmsUserFor.Reset,
event: this.isRegister ? 'register' : 'reset_pwd',
};
businessSendSms(options)
.then(() => {
+21 -20
View File
@@ -1,22 +1,23 @@
export default {
storeConversationList: (state) => state.conversation.conversationList,
storeCurrentConversation: (state) => state.conversation.currentConversation,
storeUnReadCount: (state) => state.conversation.unReadCount,
storeCurrentGroup: (state) => state.conversation.currentGroup,
storeCurrentMemberInGroup: (state) => state.conversation.currentMemberInGroup,
storeFriendList: (state) => state.contact.friendList,
storeBlackList: (state) => state.contact.blackList,
storeGroupList: (state) => state.contact.groupList,
storeRecvFriendApplications: (state) => state.contact.recvFriendApplications,
storeSentFriendApplications: (state) => state.contact.sentFriendApplications,
storeRecvGroupApplications: (state) => state.contact.recvGroupApplications,
storeSentGroupApplications: (state) => state.contact.sentGroupApplications,
storeHistoryMessageList: (state) => state.message.historyMessageList,
storeHasMoreMessage: (state) => state.message.hasMoreMessage,
storeSelfInfo: (state) => state.user.selfInfo,
storeCurrentUserID: (state) => state.user.selfInfo.userID,
storeIsSyncing: (state) => state.user.isSyncing,
storeReinstall: (state) => state.user.reinstall,
storeProgress: (state) => state.user.progress,
storeAuthData: (state) => state.user.authData,
storeConversationList: (state) => state.conversation.conversationList,
storeCurrentConversation: (state) => state.conversation.currentConversation,
storeUnReadCount: (state) => state.conversation.unReadCount,
storeCurrentGroup: (state) => state.conversation.currentGroup,
storeCurrentMemberInGroup: (state) => state.conversation.currentMemberInGroup,
storeFriendList: (state) => state.contact.friendList,
storeBlackList: (state) => state.contact.blackList,
storeGroupList: (state) => state.contact.groupList,
storeRecvFriendApplications: (state) => state.contact.recvFriendApplications,
storeSentFriendApplications: (state) => state.contact.sentFriendApplications,
storeRecvGroupApplications: (state) => state.contact.recvGroupApplications,
storeSentGroupApplications: (state) => state.contact.sentGroupApplications,
storeHistoryMessageList: (state) => state.message.historyMessageList,
storeHasMoreMessage: (state) => state.message.hasMoreMessage,
storeSelfInfo: (state) => state.user.selfInfo,
storeCurrentUserID: (state) => state.user.selfInfo.userID,
storeIsSyncing: (state) => state.user.isSyncing,
storeReinstall: (state) => state.user.reinstall,
storeProgress: (state) => state.user.progress,
storeAuthData: (state) => state.user.authData,
config: (state) => state.system.config,
};
+9 -7
View File
@@ -4,18 +4,20 @@ import user from "./modules/user";
import contact from "./modules/contact";
import conversation from "./modules/conversation";
import message from "./modules/message";
import system from "./modules/system";
import getters from "./getters";
Vue.use(Vuex);
const store = new Vuex.Store({
modules: {
user,
contact,
conversation,
message,
},
getters,
modules: {
user,
contact,
conversation,
message,
system,
},
getters,
});
export default store;
+383 -299
View File
@@ -1,320 +1,404 @@
import { v4 as uuidv4 } from "uuid";
import {
v4 as uuidv4
} from "uuid";
import IMSDK from "openim-uniapp-polyfill";
const state = {
friendList: [],
blackList: [],
groupList: [],
recvFriendApplications: [],
sentFriendApplications: [],
recvGroupApplications: [],
sentGroupApplications: [],
unHandleFriendApplicationNum: 0,
unHandleGroupApplicationNum: 0,
friendList: [],
blackList: [],
groupList: [],
recvFriendApplications: [],
sentFriendApplications: [],
recvGroupApplications: [],
sentGroupApplications: [],
unHandleFriendApplicationNum: 0,
unHandleGroupApplicationNum: 0,
};
const mutations = {
SET_FRIEND_LIST(state, list) {
state.friendList = [...list];
},
SET_BLACK_LIST(state, list) {
state.blackList = [...list];
},
SET_GROUP_LIST(state, list) {
state.groupList = [...list];
},
SET_RECV_FRIEND_APPLICATIONS(state, list) {
state.recvFriendApplications = [...list];
},
SET_SENT_FRIEND_APPLICATIONS(state, list) {
state.sentFriendApplications = [...list];
},
SET_RECV_GROUP_APPLICATIONS(state, list) {
state.recvGroupApplications = [...list];
},
SET_SENT_GROUP_APPLICATIONS(state, list) {
state.sentGroupApplications = [...list];
},
SET_FRIEND_LIST(state, list) {
state.friendList = [...list];
},
SET_BLACK_LIST(state, list) {
state.blackList = [...list];
},
SET_GROUP_LIST(state, list) {
state.groupList = [...list];
},
SET_RECV_FRIEND_APPLICATIONS(state, list) {
state.recvFriendApplications = [...list];
},
SET_SENT_FRIEND_APPLICATIONS(state, list) {
state.sentFriendApplications = [...list];
},
SET_RECV_GROUP_APPLICATIONS(state, list) {
state.recvGroupApplications = [...list];
},
SET_SENT_GROUP_APPLICATIONS(state, list) {
state.sentGroupApplications = [...list];
},
};
const actions = {
async getFriendList({ commit }) {
let offset = 0;
let friendInfoList = [];
let initialFetch = true;
while (true) {
try {
const count = initialFetch ? 10000 : 1000;
const { data } = await IMSDK.asyncApi("getFriendListPage", uuidv4(), {
offset,
count,
});
friendInfoList = [
...friendInfoList,
...data,
];
offset += count;
if (data.length < count) break;
initialFetch = false;
} catch (error) {
console.error("getFriendListPage error");
}
}
commit("SET_FRIEND_LIST", friendInfoList);
},
async getGrouplist({ commit }) {
let offset = 0;
let groupList = [];
while (true) {
try {
const { data } = await IMSDK.asyncApi(
"getJoinedGroupListPage",
uuidv4(),
{
offset,
count: 1000,
}
);
groupList = [...groupList, ...data];
offset += 1000;
if (data.length < 1000) break;
} catch (error) {
console.error("getGrouplist error");
}
}
commit("SET_GROUP_LIST", groupList);
},
getBlacklist({ commit }) {
IMSDK.asyncApi(IMSDK.IMMethods.GetBlackList, uuidv4()).then(({ data }) => {
commit("SET_BLACK_LIST", data);
});
},
getRecvFriendApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetFriendApplicationListAsRecipient,
uuidv4(),
).then(({ data }) => {
commit("SET_RECV_FRIEND_APPLICATIONS", data);
});
},
getSentFriendApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetFriendApplicationListAsApplicant,
uuidv4(),
).then(({ data }) => {
commit("SET_SENT_FRIEND_APPLICATIONS", data);
});
},
getRecvGroupApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetGroupApplicationListAsRecipient,
uuidv4(),
).then(({ data }) => {
commit("SET_RECV_GROUP_APPLICATIONS", data);
});
},
getSentGroupApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetGroupApplicationListAsApplicant,
uuidv4(),
).then(({ data }) => {
commit("SET_SENT_GROUP_APPLICATIONS", data);
});
},
pushNewFriend({ commit, state }, friendInfo) {
const tmpList = [...state.friendList];
const idx = tmpList.findIndex((item) => item.userID === friendInfo.userID);
if (idx === -1) {
commit("SET_FRIEND_LIST", [...tmpList, friendInfo]);
}
},
updateFriendInfo({ commit, state }, { friendInfo, isRemove = false }) {
const tmpList = [...state.friendList];
const idx = tmpList.findIndex((item) => item.userID === friendInfo.userID);
async getFriendList({
commit
}) {
let offset = 0;
let friendInfoList = [];
let initialFetch = true;
while (true) {
try {
const count = initialFetch ? 10000 : 1000;
const {
data
} = await IMSDK.asyncApi("getFriendListPage", uuidv4(), {
offset,
count,
});
friendInfoList = [
...friendInfoList,
...data,
];
offset += count;
if (data.length < count) break;
initialFetch = false;
} catch (error) {
console.error("getFriendListPage error");
}
}
commit("SET_FRIEND_LIST", friendInfoList);
},
async getGrouplist({
commit
}) {
let offset = 0;
let groupList = [];
while (true) {
try {
const {
data
} = await IMSDK.asyncApi(
"getJoinedGroupListPage",
uuidv4(), {
offset,
count: 1000,
}
);
groupList = [...groupList, ...data];
offset += 1000;
if (data.length < 1000) break;
} catch (error) {
console.error("getGrouplist error");
}
}
commit("SET_GROUP_LIST", groupList);
},
getBlacklist({
commit
}) {
IMSDK.asyncApi(IMSDK.IMMethods.GetBlackList, uuidv4()).then(({
data
}) => {
commit("SET_BLACK_LIST", data);
});
},
getRecvFriendApplications({
commit
}) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetFriendApplicationListAsRecipient,
uuidv4(),
).then(({
data
}) => {
commit("SET_RECV_FRIEND_APPLICATIONS", data);
});
},
getSentFriendApplications({
commit
}) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetFriendApplicationListAsApplicant,
uuidv4(),
).then(({
data
}) => {
commit("SET_SENT_FRIEND_APPLICATIONS", data);
});
},
getRecvGroupApplications({
commit
}) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetGroupApplicationListAsRecipient,
uuidv4(),
).then(({
data
}) => {
commit("SET_RECV_GROUP_APPLICATIONS", data);
});
},
getSentGroupApplications({
commit
}) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetGroupApplicationListAsApplicant,
uuidv4(),
).then(({
data
}) => {
commit("SET_SENT_GROUP_APPLICATIONS", data);
});
},
pushNewFriend({
commit,
state
}, friendInfo) {
const tmpList = [...state.friendList];
const idx = tmpList.findIndex((item) => item.userID === friendInfo.userID);
if (idx === -1) {
commit("SET_FRIEND_LIST", [...tmpList, friendInfo]);
}
},
updateFriendInfo({
commit,
state
}, {
friendInfo,
isRemove = false
}) {
const tmpList = [...state.friendList];
const idx = tmpList.findIndex((item) => item.userID === friendInfo.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...friendInfo,
};
}
commit("SET_FRIEND_LIST", tmpList);
}
},
pushNewBlack({ commit, state }, blackInfo) {
const tmpList = [...state.blackList];
const idx = tmpList.findIndex((item) => item.userID === blackInfo.userID);
if (idx === -1) {
commit("SET_BLACK_LIST", [...tmpList, blackInfo]);
}
},
updateBlackInfo({ commit, state }, { blackInfo, isRemove = false }) {
const tmpList = [...state.blackList];
const idx = tmpList.findIndex((item) => item.userID === blackInfo.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...friendInfo,
};
}
commit("SET_FRIEND_LIST", tmpList);
}
},
pushNewBlack({
commit,
state
}, blackInfo) {
const tmpList = [...state.blackList];
const idx = tmpList.findIndex((item) => item.userID === blackInfo.userID);
if (idx === -1) {
commit("SET_BLACK_LIST", [...tmpList, blackInfo]);
}
},
updateBlackInfo({
commit,
state
}, {
blackInfo,
isRemove = false
}) {
const tmpList = [...state.blackList];
const idx = tmpList.findIndex((item) => item.userID === blackInfo.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...blackInfo,
};
}
commit("SET_BLACK_LIST", tmpList);
}
},
pushNewGroup({ commit, state }, groupInfo) {
const tmpList = [...state.groupList];
const idx = tmpList.findIndex((item) => item.groupID === groupInfo.groupID);
if (idx === -1) {
commit("SET_GROUP_LIST", [...tmpList, groupInfo]);
}
},
updateGroupInfo(
{ commit, state, rootState },
{ groupInfo, isRemove = false },
) {
const tmpList = [...state.groupList];
const idx = tmpList.findIndex((item) => item.groupID === groupInfo.groupID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...blackInfo,
};
}
commit("SET_BLACK_LIST", tmpList);
}
},
pushNewGroup({
commit,
state
}, groupInfo) {
const tmpList = [...state.groupList];
const idx = tmpList.findIndex((item) => item.groupID === groupInfo.groupID);
if (idx === -1) {
commit("SET_GROUP_LIST", [...tmpList, groupInfo]);
}
},
updateGroupInfo({
commit,
state,
rootState
}, {
groupInfo,
isRemove = false
}, ) {
const tmpList = [...state.groupList];
const idx = tmpList.findIndex((item) => item.groupID === groupInfo.groupID);
if (rootState.conversation.currentGroup.groupID === groupInfo.groupID) {
commit("conversation/SET_CURRENT_GROUP", groupInfo, { root: true });
}
if (rootState.conversation.currentGroup.groupID === groupInfo.groupID) {
commit("conversation/SET_CURRENT_GROUP", groupInfo, {
root: true
});
}
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...groupInfo,
};
}
commit("SET_GROUP_LIST", tmpList);
}
},
pushNewRecvFriendApplition({ commit, state }, application) {
const tmpList = [...state.recvFriendApplications];
const idx = tmpList.findIndex(
(item) => item.fromUserID === application.fromUserID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_RECV_FRIEND_APPLICATIONS", [...tmpList, application]);
},
updateRecvFriendApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.recvFriendApplications];
const idx = tmpList.findIndex(
(item) => item.fromUserID === application.fromUserID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...groupInfo,
};
}
commit("SET_GROUP_LIST", tmpList);
}
},
pushNewRecvFriendApplition({
commit,
state
}, application) {
const tmpList = [...state.recvFriendApplications];
const idx = tmpList.findIndex(
(item) => item.fromUserID === application.fromUserID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_RECV_FRIEND_APPLICATIONS", [...tmpList, application]);
},
updateRecvFriendApplition({
commit,
state,
rootState
}, {
application,
isRemove = false
}, ) {
const tmpList = [...state.recvFriendApplications];
const idx = tmpList.findIndex(
(item) => item.fromUserID === application.fromUserID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_RECV_FRIEND_APPLICATIONS", tmpList);
}
},
pushNewSentFriendApplition({ commit, state }, application) {
const tmpList = [...state.sentFriendApplications];
const idx = tmpList.findIndex(
(item) => item.toUserID === application.toUserID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_SENT_FRIEND_APPLICATIONS", [...tmpList, application]);
},
updateSentFriendApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.sentFriendApplications];
const idx = tmpList.findIndex(
(item) => item.toUserID === application.toUserID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_RECV_FRIEND_APPLICATIONS", tmpList);
}
},
pushNewSentFriendApplition({
commit,
state
}, application) {
const tmpList = [...state.sentFriendApplications];
const idx = tmpList.findIndex(
(item) => item.toUserID === application.toUserID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_SENT_FRIEND_APPLICATIONS", [...tmpList, application]);
},
updateSentFriendApplition({
commit,
state,
rootState
}, {
application,
isRemove = false
}, ) {
const tmpList = [...state.sentFriendApplications];
const idx = tmpList.findIndex(
(item) => item.toUserID === application.toUserID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_SENT_FRIEND_APPLICATIONS", tmpList);
}
},
pushNewRecvGroupApplition({ commit, state }, application) {
const tmpList = [...state.recvGroupApplications];
const idx = tmpList.findIndex((item) => item.userID === application.userID);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_RECV_GROUP_APPLICATIONS", [...tmpList, application]);
},
updateRecvGroupApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.recvGroupApplications];
const idx = tmpList.findIndex((item) => item.userID === application.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_SENT_FRIEND_APPLICATIONS", tmpList);
}
},
pushNewRecvGroupApplition({
commit,
state
}, application) {
const tmpList = [...state.recvGroupApplications];
const idx = tmpList.findIndex((item) => item.userID === application.userID);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_RECV_GROUP_APPLICATIONS", [...tmpList, application]);
},
updateRecvGroupApplition({
commit,
state,
rootState
}, {
application,
isRemove = false
}, ) {
const tmpList = [...state.recvGroupApplications];
const idx = tmpList.findIndex((item) => item.userID === application.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_RECV_GROUP_APPLICATIONS", tmpList);
}
},
pushNewSentGroupApplition({ commit, state }, application) {
const tmpList = [...state.sentGroupApplications];
const idx = tmpList.findIndex(
(item) => item.groupID === application.groupID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_SENT_GROUP_APPLICATIONS", [...tmpList, application]);
},
updateSentGroupApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.sentGroupApplications];
const idx = tmpList.findIndex(
(item) => item.groupID === application.groupID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_RECV_GROUP_APPLICATIONS", tmpList);
}
},
pushNewSentGroupApplition({
commit,
state
}, application) {
const tmpList = [...state.sentGroupApplications];
const idx = tmpList.findIndex(
(item) => item.groupID === application.groupID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_SENT_GROUP_APPLICATIONS", [...tmpList, application]);
},
updateSentGroupApplition({
commit,
state,
rootState
}, {
application,
isRemove = false
}, ) {
const tmpList = [...state.sentGroupApplications];
const idx = tmpList.findIndex(
(item) => item.groupID === application.groupID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_SENT_GROUP_APPLICATIONS", tmpList);
}
},
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_SENT_GROUP_APPLICATIONS", tmpList);
}
},
};
export default {
namespaced: true,
state,
mutations,
actions,
namespaced: true,
state,
mutations,
actions,
};
+21 -6
View File
@@ -46,7 +46,10 @@ const mutations = {
};
const actions = {
async getConversationList({ state, commit }, isFirstPage = true) {
async getConversationList({
state,
commit
}, isFirstPage = true) {
try {
const {
data
@@ -68,7 +71,9 @@ const actions = {
return [];
}
},
getCurrentGroup({ commit }, groupID) {
getCurrentGroup({
commit
}, groupID) {
IMSDK.asyncApi(IMSDK.IMMethods.GetSpecifiedGroupsInfo, uuidv4(), [
groupID,
]).then(({
@@ -77,7 +82,10 @@ const actions = {
commit("SET_CURRENT_GROUP", data[0] ?? {});
});
},
getCurrentMemberInGroup({ commit, rootState }, groupID) {
getCurrentMemberInGroup({
commit,
rootState
}, groupID) {
IMSDK.asyncApi(IMSDK.IMMethods.GetSpecifiedGroupMembersInfo, uuidv4(), {
groupID,
userIDList: [rootState.user.selfInfo.userID],
@@ -87,7 +95,9 @@ const actions = {
commit("SET_CURRENT_MEMBER_IN_GROUP", data[0] ?? {});
});
},
getUnReadCount({ commit }) {
getUnReadCount({
commit
}) {
IMSDK.asyncApi(IMSDK.IMMethods.GetTotalUnreadMsgCount, uuidv4()).then(
(res) => {
console.log(res);
@@ -95,7 +105,10 @@ const actions = {
},
);
},
updateCurrentMemberInGroup({ commit, state }, memberInfo) {
updateCurrentMemberInGroup({
commit,
state
}, memberInfo) {
console.log(memberInfo);
if (
memberInfo.groupID === state.currentMemberInGroup.groupID &&
@@ -104,7 +117,9 @@ const actions = {
commit("SET_CURRENT_MEMBER_IN_GROUP", memberInfo);
}
},
resetConversationState({ commit }) {
resetConversationState({
commit
}) {
commit("SET_CURRENT_MEMBER_IN_GROUP", {});
commit("SET_CURRENT_GROUP", {});
commit("SET_CURRENT_CONVERSATION", {});
+92 -75
View File
@@ -1,87 +1,104 @@
import IMSDK, { MessageStatus, MessageType } from "openim-uniapp-polyfill";
import { v4 as uuidv4 } from "uuid";
import { UpdateMessageTypes } from "@/constant";
import IMSDK, {
MessageStatus,
MessageType
} from "openim-uniapp-polyfill";
import {
v4 as uuidv4
} from "uuid";
import {
UpdateMessageTypes
} from "@/constant";
const state = {
historyMessageList: [],
hasMoreMessage: true,
historyMessageList: [],
hasMoreMessage: true,
};
const mutations = {
SET_HISTORY_MESSAGE_LIST(state, list) {
state.historyMessageList = [...list];
},
SET_HAS_MORE_MESSAGE(state, hasMore) {
state.hasMoreMessage = hasMore;
},
SET_HISTORY_MESSAGE_LIST(state, list) {
state.historyMessageList = [...list];
},
SET_HAS_MORE_MESSAGE(state, hasMore) {
state.hasMoreMessage = hasMore;
},
};
const actions = {
async getHistoryMesageList({ commit, state }, params) {
let emptyFlag = true;
try {
console.log("getHistoryMesageList:::");
console.log(params);
const { data } = await IMSDK.asyncApi(
IMSDK.IMMethods.GetAdvancedHistoryMessageList,
uuidv4(),
params,
);
console.log(data);
const isFistPage = !params.startClientMsgID
const messages = data.messageList ?? [];
emptyFlag = messages.length === 0;
commit("SET_HISTORY_MESSAGE_LIST", [
...messages,
...(isFistPage ? [] : state.historyMessageList),
]);
commit("SET_HAS_MORE_MESSAGE", !data.isEnd && messages.length === 20);
} catch (e) {
commit("SET_HISTORY_MESSAGE_LIST", []);
}
return {
emptyFlag,
};
},
pushNewMessage({ commit, state }, message) {
commit("SET_HISTORY_MESSAGE_LIST", [...state.historyMessageList, message]);
},
updateOneMessage(
{ commit, state },
{
message,
type = UpdateMessageTypes.Overall,
keyWords = [],
isSuccess = false,
},
) {
const tmpList = state.historyMessageList;
const idx = tmpList.findIndex(
(msg) => msg.clientMsgID === message.clientMsgID,
);
if (idx !== -1) {
if (type === UpdateMessageTypes.Overall) {
tmpList[idx] = {
...message,
};
} else if (type === UpdateMessageTypes.KeyWords) {
const updateFields = Array.isArray(keyWords) ? keyWords : [keyWords];
updateFields.forEach(
(field) => (tmpList[idx][field.key] = field.value),
);
}
commit("SET_HISTORY_MESSAGE_LIST", tmpList);
}
},
resetMessageState({ commit }) {
commit("SET_HISTORY_MESSAGE_LIST", []);
commit("SET_HAS_MORE_MESSAGE", true);
},
async getHistoryMesageList({
commit,
state
}, params) {
let emptyFlag = true;
try {
console.log("getHistoryMesageList:::");
console.log(params);
const {
data
} = await IMSDK.asyncApi(
IMSDK.IMMethods.GetAdvancedHistoryMessageList,
uuidv4(),
params,
);
console.log(data);
const isFistPage = !params.startClientMsgID
const messages = data.messageList ?? [];
emptyFlag = messages.length === 0;
commit("SET_HISTORY_MESSAGE_LIST", [
...messages,
...(isFistPage ? [] : state.historyMessageList),
]);
commit("SET_HAS_MORE_MESSAGE", !data.isEnd && messages.length === 20);
} catch (e) {
commit("SET_HISTORY_MESSAGE_LIST", []);
}
return {
emptyFlag,
};
},
pushNewMessage({
commit,
state
}, message) {
commit("SET_HISTORY_MESSAGE_LIST", [...state.historyMessageList, message]);
},
updateOneMessage({
commit,
state
}, {
message,
type = UpdateMessageTypes.Overall,
keyWords = [],
isSuccess = false,
}, ) {
const tmpList = state.historyMessageList;
const idx = tmpList.findIndex(
(msg) => msg.clientMsgID === message.clientMsgID,
);
if (idx !== -1) {
if (type === UpdateMessageTypes.Overall) {
tmpList[idx] = {
...message,
};
} else if (type === UpdateMessageTypes.KeyWords) {
const updateFields = Array.isArray(keyWords) ? keyWords : [keyWords];
updateFields.forEach(
(field) => (tmpList[idx][field.key] = field.value),
);
}
commit("SET_HISTORY_MESSAGE_LIST", tmpList);
}
},
resetMessageState({
commit
}) {
commit("SET_HISTORY_MESSAGE_LIST", []);
commit("SET_HAS_MORE_MESSAGE", true);
},
};
export default {
namespaced: true,
state,
mutations,
actions,
namespaced: true,
state,
mutations,
actions,
};
+42
View File
@@ -0,0 +1,42 @@
import IMSDK from "openim-uniapp-polyfill";
import {
businessConfig
} from "@/api/login";
import {
filterEmptyValue
} from "@/util/common";
const state = {
config: {}
};
const mutations = {
SET_CONFIG(state, info) {
state.config = {
...info,
};
}
};
const actions = {
async getConfig({
commit
}) {
try {
const data = await businessConfig();
//filterEmptyValue(businessData);
commit("SET_CONFIG", data);
} catch (e) {
console.log(e);
uni.$u.toast("获取系统信息失败");
}
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};
+19 -5
View File
@@ -1,7 +1,13 @@
import { v4 as uuidv4} from "uuid";
import {
v4 as uuidv4
} from "uuid";
import IMSDK from "openim-uniapp-polyfill";
import { businessGetUserInfo} from "@/api/login";
import { filterEmptyValue} from "@/util/common";
import {
businessGetUserInfo
} from "@/api/login";
import {
filterEmptyValue
} from "@/util/common";
const state = {
selfInfo: {},
@@ -9,9 +15,13 @@ const state = {
isSyncing: false,
reinstall: false,
progress: 0,
token: ""
};
const mutations = {
SET_TOKEN(state, info) {
state.token = info;
},
SET_SELF_INFO(state, info) {
state.selfInfo = {
...info,
@@ -34,7 +44,9 @@ const mutations = {
};
const actions = {
async getSelfInfo({ commit }) {
async getSelfInfo({
commit
}) {
try {
const {
data
@@ -42,7 +54,9 @@ const actions = {
IMSDK.IMMethods.GetSelfUserInfo,
uuidv4(),
);
const {users} = await businessGetUserInfo(data.userID);
const {
users
} = await businessGetUserInfo(data.userID);
console.log(users);
const businessData = users[0] ?? {};
filterEmptyValue(businessData);
@@ -1,11 +1,6 @@
// 此版本发布于2022-00-24
const version = '2.0.34'
// 开发环境才提示,生产环境不会提示
if (process.env.NODE_ENV === 'development') {
console.log(`\n %c uView V${version} %c https://uviewui.com/ \n\n`, 'color: #ffffff; background: #3c9cff; padding:5px 0; border-radius: 5px;');
}
export default {
v: version,
version,
+181 -179
View File
@@ -1,213 +1,215 @@
import PinYin from "./pinyin";
export const html2Text = (html) => {
if (!html) {
return "";
}
return html
.replace(/<\/p><p>/g, "\n")
.replace(/\&nbsp;/g, " ")
.replace(/<p>/g, "")
.replace(/<\/p>/g, "")
.replace(/<br>/g, "")
.trim();
if (!html) {
return "";
}
return html
.replace(/<\/p><p>/g, "\n")
.replace(/\&nbsp;/g, " ")
.replace(/<p>/g, "")
.replace(/<\/p>/g, "")
.replace(/<br>/g, "")
.trim();
};
export const parseBr = (content) => {
if (!content) {
return "";
}
return content.replace(/\n/g, "\\n").trim();
if (!content) {
return "";
}
return content.replace(/\n/g, "\\n").trim();
};
export const getEl = (el) => {
return new Promise((resolve) => {
const query = uni.createSelectorQuery().in(this);
query
.select(el)
.boundingClientRect((data) => {
// 存在data,且存在宽和高,视为渲染完毕
resolve(data);
})
.exec();
});
return new Promise((resolve) => {
const query = uni.createSelectorQuery().in(this);
query
.select(el)
.boundingClientRect((data) => {
// 存在data,且存在宽和高,视为渲染完毕
resolve(data);
})
.exec();
});
};
export const getDbDir = () => {
return new Promise((resolve, reject) => {
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
fs.root.getDirectory(
"user",
{
create: true,
},
(entry) => {
resolve(entry.fullPath);
},
(error) => {
reject(error);
},
);
});
});
return new Promise((resolve, reject) => {
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
fs.root.getDirectory(
"user", {
create: true,
},
(entry) => {
resolve(entry.fullPath);
},
(error) => {
reject(error);
},
);
});
});
};
export const formatChooseData = (data, key = "nickname") => {
const ucfirst = (l1) => {
if (l1.length > 0) {
var first = l1.substr(0, 1).toUpperCase();
var spare = l1.substr(1, l1.length);
return first + spare;
}
};
const ucfirst = (l1) => {
if (l1.length > 0) {
var first = l1.substr(0, 1).toUpperCase();
var spare = l1.substr(1, l1.length);
return first + spare;
}
};
const arraySearch = (l1, l2) => {
for (var name in PinYin) {
if (PinYin[name].indexOf(l1) != -1) {
return ucfirst(name);
break;
}
}
return false;
};
const arraySearch = (l1, l2) => {
for (var name in PinYin) {
if (PinYin[name].indexOf(l1) != -1) {
return ucfirst(name);
break;
}
}
return false;
};
const codefans = (l1) => {
l1 = l1 ?? "unkown";
var l2 = l1.length;
var I1 = "";
var reg = new RegExp("[a-zA-Z0-9- ]");
for (var i = 0; i < l2; i++) {
var val = l1.substr(i, 1);
var name = arraySearch(val, PinYin);
if (reg.test(val)) {
I1 += val;
} else if (name !== false) {
I1 += name;
}
}
I1 = I1.replace(/ /g, "-");
while (I1.indexOf("--") > 0) {
I1 = I1.replace("--", "-");
}
return I1;
};
const codefans = (l1) => {
l1 = l1 ?? "unkown";
var l2 = l1.length;
var I1 = "";
var reg = new RegExp("[a-zA-Z0-9- ]");
for (var i = 0; i < l2; i++) {
var val = l1.substr(i, 1);
var name = arraySearch(val, PinYin);
if (reg.test(val)) {
I1 += val;
} else if (name !== false) {
I1 += name;
}
}
I1 = I1.replace(/ /g, "-");
while (I1.indexOf("--") > 0) {
I1 = I1.replace("--", "-");
}
return I1;
};
var arr = [],
firstName;
var arr = [],
firstName;
for (var i = 0; i < data.length; i++) {
firstName = data[i].initial = codefans(data[i][key]).substr(0, 1);
arr.push(firstName.toUpperCase());
}
for (var i = 0; i < data.length; i++) {
firstName = data[i].initial = codefans(data[i][key]).substr(0, 1);
arr.push(firstName.toUpperCase());
}
var arrlist = [];
for (i = 0; i < arr.length; i++) {
if (arrlist.indexOf(arr[i]) == -1) {
arrlist.push(arr[i]);
}
}
var arrlist = [];
for (i = 0; i < arr.length; i++) {
if (arrlist.indexOf(arr[i]) == -1) {
arrlist.push(arr[i]);
}
}
var dataSort = [];
for (var i = 0; i < arrlist.length; i++) {
dataSort[i] = {
initial: arrlist[i],
};
dataSort[i].data = [];
for (var j = 0; j < data.length; j++) {
if (data[j].initial.toUpperCase() == dataSort[i].initial) {
dataSort[i].data.push(data[j]);
}
}
}
for (var i = 0; i < dataSort.length - 1; i++) {
for (var j = 1; j < dataSort.length - i; j++) {
if (dataSort[j - 1].initial > dataSort[j].initial) {
var a = dataSort[j];
dataSort[j] = dataSort[j - 1];
dataSort[j - 1] = a;
}
}
}
const NomalInitial = "QWERTYUIOPLKJHGFDSAZXCVBNM".split("");
const special = {
initial: "#",
data: [],
};
const newFilterData = dataSort.filter((d) => {
if (!NomalInitial.includes(d.initial)) {
special.data = [...special.data, ...d.data];
} else {
return d;
}
});
if (special.data.length > 0) {
newFilterData.push(special);
}
const indexList = newFilterData.map((item) => item.initial);
const dataList = newFilterData.map((item) => item.data);
return {
indexList,
dataList,
};
var dataSort = [];
for (var i = 0; i < arrlist.length; i++) {
dataSort[i] = {
initial: arrlist[i],
};
dataSort[i].data = [];
for (var j = 0; j < data.length; j++) {
if (data[j].initial.toUpperCase() == dataSort[i].initial) {
dataSort[i].data.push(data[j]);
}
}
}
for (var i = 0; i < dataSort.length - 1; i++) {
for (var j = 1; j < dataSort.length - i; j++) {
if (dataSort[j - 1].initial > dataSort[j].initial) {
var a = dataSort[j];
dataSort[j] = dataSort[j - 1];
dataSort[j - 1] = a;
}
}
}
const NomalInitial = "QWERTYUIOPLKJHGFDSAZXCVBNM".split("");
const special = {
initial: "#",
data: [],
};
const newFilterData = dataSort.filter((d) => {
if (!NomalInitial.includes(d.initial)) {
special.data = [...special.data, ...d.data];
} else {
return d;
}
});
if (special.data.length > 0) {
newFilterData.push(special);
}
const indexList = newFilterData.map((item) => item.initial);
const dataList = newFilterData.map((item) => item.data);
return {
indexList,
dataList,
};
};
export const getPurePath = (path) => {
const prefix = "file://";
const relativeRrefix = "_doc/";
if (path.includes(prefix)) {
path = path.replace(prefix, "");
}
if (path.includes(relativeRrefix)) {
path = plus.io.convertLocalFileSystemURL(path);
}
return path;
const prefix = "file://";
const relativeRrefix = "_doc/";
if (path.includes(prefix)) {
path = path.replace(prefix, "");
}
if (path.includes(relativeRrefix)) {
path = plus.io.convertLocalFileSystemURL(path);
}
return path;
};
export const filterEmptyValue = (obj) => {
for (let key in obj) {
if (obj[key] === "") {
delete obj[key];
}
}
for (let key in obj) {
if (obj[key] === "") {
delete obj[key];
}
}
};
export const toastWithCallback = (message, callBack, duration = 1000) => {
uni.$u.toast(message);
setTimeout(callBack, duration);
uni.$u.toast(message);
setTimeout(callBack, duration);
};
export const checkLoginError = (error) => {
if (!error?.errCode) {
return "操作失败";
}
switch (error.errCode) {
case 20001:
return "密码错误";
case 20002:
return "账号不存在";
case 20003:
return "手机号已经注册";
case 20004:
return "账号已注册";
case 20005:
return "操作过于频繁,请稍后再试";
case 20006:
return "验证码错误";
case 20007:
return "验证码过期";
case 20008:
return "验证码错误次数超过限制,请稍后再试";
case 20009:
return "验证码已被使用";
case 20010:
return "邀请码已被使用";
case 20011:
return "邀请码不存在";
case 20012:
return "操作限制";
case 20014:
return "账号已注册";
default:
return "操作失败";
}
if (error?.msg) {
return error.msg
}
if (!error?.errCode) {
return "操作失败";
}
switch (error.errCode) {
case 20001:
return "密码错误";
case 20002:
return "账号不存在";
case 20003:
return "手机号已经注册";
case 20004:
return "账号已注册";
case 20005:
return "操作过于频繁,请稍后再试";
case 20006:
return "验证码错误";
case 20007:
return "验证码过期";
case 20008:
return "验证码错误次数超过限制,请稍后再试";
case 20009:
return "验证码已被使用";
case 20010:
return "邀请码已被使用";
case 20011:
return "邀请码不存在";
case 20012:
return "操作限制";
case 20014:
return "账号已注册";
default:
return "操作失败";
}
};
+5 -5
View File
@@ -2,12 +2,12 @@
import config from "@/common/config";
// 初始化请求配置
uni.$u.http.setConfig((defaultConfig) => {
/* defaultConfig 为默认全局配置 */
defaultConfig.baseURL = config.getRegisterUrl(); /* 根域名 */
return defaultConfig;
/* defaultConfig 为默认全局配置 */
defaultConfig.baseURL = config.getRegisterUrl(); /* 根域名 */
return defaultConfig;
});
module.exports = (vm) => {
require("./requestInterceptors")(vm);
require("./responseInterceptors")(vm);
require("./requestInterceptors")(vm);
require("./responseInterceptors")(vm);
};
+23 -23
View File
@@ -1,30 +1,30 @@
import appConfig from "@/common/config";
import { v4 as uuidV4 } from "uuid";
import {
v4 as uuidV4
} from "uuid";
/**
* 请求拦截
* @param {Object} http
*/
module.exports = (vm) => {
uni.$u.http.interceptors.request.use(
(config) => {
// 可使用async await 做异步操作
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
config.data = config.data || {};
if (config.custom.isIMApi) {
config.baseURL = appConfig.getApiUrl();
}
if (config.custom.isPgyerApi) {
config.baseURL = "https://www.pgyer.com";
}
config.header = {
...config.header,
operationID: uuidV4(),
};
// 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
return config;
},
(
config, // 可使用async await 做异步操作
) => Promise.reject(config),
);
uni.$u.http.interceptors.request.use(
(config) => {
// 可使用async await 做异步操作
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
config.data = config.data || {};
if (config.custom.isIMApi) {
config.baseURL = appConfig.getApiUrl();
}
config.header = {
...config.header,
token:uni.getStorageSync("BusinessToken"),
operationID: uuidV4(),
};
// 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
return config;
},
(
config, // 可使用async await 做异步操作
) => Promise.reject(config),
);
};
+38 -28
View File
@@ -3,32 +3,42 @@
* @param {Object} http
*/
module.exports = (vm) => {
uni.$u.http.interceptors.response.use(
(response) => {
/* 对响应成功做点什么 可使用async await 做异步操作*/
const data = response.data;
// 自定义参数
const custom = response.config?.custom;
if (data.errCode !== 0 && data.code !== 0) {
// 服务端返回的状态码不等于200,则reject()
// 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
// if (custom.toast !== false) {
// uni.$u.toast(data.message)
// }
// 如果需要catch返回,则进行reject
// if (custom?.catch) {
console.error('http catch rejected', data)
return Promise.reject(data);
// } else {
// // 否则返回一个pending中的promise
// return new Promise(() => { })
// }
}
return data.data || {};
},
(response) => {
/* 对响应错误做点什么 statusCode !== 200*/
return Promise.reject(response);
},
);
uni.$u.http.interceptors.response.use((response) => {
console.log("\n-"
+"\n============================================================="
+"\nurl:"+response.config.fullPath
+"\nparams:"+JSON.stringify(response.config.params)
+"\ndata:"+JSON.stringify(response.config.data)
+"\nheader:"+JSON.stringify(response.config.header)
+"\nresponse:"+JSON.stringify(response.data)
+"\n=============================================================\n");
/* 对响应成功做点什么 可使用async await 做异步操作*/
const data = response.data;
// 自定义参数
const custom = response.config?.custom;
if (data.errCode !== 0 && data.code !== 0) {
if(data?.msg){
uni.$u.toast(data.msg)
}
// 服务端返回的状态码不等于200,则reject()
// 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
// if (custom.toast !== false) {
// uni.$u.toast(data.message)
// }
// 如果需要catch返回,则进行reject
// if (custom?.catch) {
console.error('http catch rejected', data)
return Promise.reject(data);
// } else {
// // 否则返回一个pending中的promise
// return new Promise(() => { })
// }
}
return data.data || {};
},
(response) => {
/* 对响应错误做点什么 statusCode !== 200*/
return Promise.reject(response);
},
);
};