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