IM部分处理

This commit is contained in:
abu 2025-04-30 14:28:07 +08:00
parent eaa9f50e7a
commit 192f493535
22 changed files with 2957 additions and 2398 deletions

16
App.vue
View File

@ -11,8 +11,14 @@ import provinceList from './json/area_province.js';
import cityList from './json/area_city.js'; import cityList from './json/area_city.js';
import districtList from './json/area_district.js'; import districtList from './json/area_district.js';
import storage from '@/utils/storage.js'; // import storage from '@/utils/storage.js'; //
//im
import { TUIChatKit } from '@/TUIKit';
import { loginIm } from '@/utils/handleim.js';
export default { export default {
//
globalData: {
chat: null
},
data() { data() {
return { return {
config config
@ -56,6 +62,14 @@ export default {
plus.globalEvent.addEventListener('newintent', (e) => { plus.globalEvent.addEventListener('newintent', (e) => {
this.checkArguments(); // this.checkArguments(); //
}); });
// init im
var ddd = TUIChatKit.init();
console.log('dasjdlasjdlajsldjaslkdjasljdklasdljasldadjaldjlkasdlkasjdalsdjl', ddd);
//
console.log('是否登录', storage.getHasLogin());
if (storage.getHasLogin()) {
loginIm();
}
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN

View File

@ -8,7 +8,9 @@
v-if="extension.hyperlinks_text" v-if="extension.hyperlinks_text"
:href="extension.hyperlinks_text.value" :href="extension.hyperlinks_text.value"
target="view_window" target="view_window"
>{{ extension.hyperlinks_text.key }}</a> >
{{ extension.hyperlinks_text.key }}
</a>
</h1> </h1>
<ul v-if="extension.item && extension.item.length > 0"> <ul v-if="extension.item && extension.item.length > 0">
<li <li
@ -19,7 +21,9 @@
v-if="isUrl(item.value)" v-if="isUrl(item.value)"
:href="item.value" :href="item.value"
target="view_window" target="view_window"
>{{ item.key }}</a> >
{{ item.key }}
</a>
<p v-else> <p v-else>
{{ item.key }} {{ item.key }}
</p> </p>
@ -30,7 +34,7 @@
</template> </template>
<template v-else-if="customData.businessID === CHAT_MSG_CUSTOM_TYPE.EVALUATE"> <template v-else-if="customData.businessID === CHAT_MSG_CUSTOM_TYPE.EVALUATE">
<div class="evaluate"> <div class="evaluate">
<h1>{{ TUITranslateService.t("message.custom.对本次服务评价") }}</h1> <h1>{{ TUITranslateService.t('message.custom.对本次服务评价') }}</h1>
<ul class="evaluate-list"> <ul class="evaluate-list">
<li <li
v-for="(item, index) in Math.max(customData.score, 0)" v-for="(item, index) in Math.max(customData.score, 0)"
@ -46,14 +50,27 @@
<article>{{ customData.comment }}</article> <article>{{ customData.comment }}</article>
</div> </div>
</template> </template>
<!-- 自定义视频消息 -->
<template v-else-if="customData.businessID === 'video'">
<div
class="order"
@click="openRouter(customData.link)"
>
<img :src="customData.imageUrl" />
<main>
<h1>{{ customData.title }}</h1>
<p>{{ customData.description }}</p>
<span>{{ customData.price }}</span>
</main>
</div>
</template>
<template v-else-if="customData.businessID === CHAT_MSG_CUSTOM_TYPE.ORDER"> <template v-else-if="customData.businessID === CHAT_MSG_CUSTOM_TYPE.ORDER">
<div <div
class="order" class="order"
@click="openLink(customData.link)" @click="openLink(customData.link)"
> >
<img <img :src="customData.imageUrl" />
:src="customData.imageUrl"
>
<main> <main>
<h1>{{ customData.title }}</h1> <h1>{{ customData.title }}</h1>
<p>{{ customData.description }}</p> <p>{{ customData.description }}</p>
@ -67,9 +84,9 @@
<a <a
:href="customData.link" :href="customData.link"
target="view_window" target="view_window"
>{{ >
TUITranslateService.t("message.custom.查看详情>>") {{ TUITranslateService.t('message.custom.查看详情>>') }}
}}</a> </a>
</div> </div>
</template> </template>
<template v-else> <template v-else>
@ -80,6 +97,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { watchEffect, ref } from '../../../../adapter-vue'; import { watchEffect, ref } from '../../../../adapter-vue';
import { TUIGlobal } from '@tencentcloud/universal-api';
import { TUITranslateService, IMessageModel } from '@tencentcloud/chat-uikit-engine'; import { TUITranslateService, IMessageModel } from '@tencentcloud/chat-uikit-engine';
import { isUrl, JSONToObject } from '../../../../utils/index'; import { isUrl, JSONToObject } from '../../../../utils/index';
import { CHAT_MSG_CUSTOM_TYPE } from '../../../../constant'; import { CHAT_MSG_CUSTOM_TYPE } from '../../../../constant';
@ -93,14 +111,14 @@ interface Props {
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
messageItem: undefined, messageItem: undefined,
content: undefined, content: undefined
}); });
const custom = ref(); const custom = ref();
const message = ref<IMessageModel>(); const message = ref<IMessageModel>();
const extension = ref(); const extension = ref();
const customData = ref<ICustomMessagePayload>({ const customData = ref<ICustomMessagePayload>({
businessID: '', businessID: ''
}); });
watchEffect(() => { watchEffect(() => {
@ -116,9 +134,14 @@ watchEffect(() => {
const openLink = (url: any) => { const openLink = (url: any) => {
window.open(url); window.open(url);
}; };
const openRouter = (url: any) => {
TUIGlobal.navigateTo({
url
});
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "../../../../assets/styles/common"; @import '../../../../assets/styles/common';
a { a {
color: #679ce1; color: #679ce1;

View File

@ -14,18 +14,14 @@
v-for="(conversation, index) in conversationList" v-for="(conversation, index) in conversationList"
:id="`convlistitem-${index}`" :id="`convlistitem-${index}`"
:key="index" :key="index"
:class="[ :class="['tui-conversation-content', isMobile && 'tui-conversation-content-h5 disable-select']"
'tui-conversation-content',
isMobile && 'tui-conversation-content-h5 disable-select',
]"
> >
<div <div
:class="[ :class="[
isPC && 'isPC', isPC && 'isPC',
'tui-conversation-item', 'tui-conversation-item',
currentConversationID === conversation.conversationID && currentConversationID === conversation.conversationID && 'tui-conversation-item-selected',
'tui-conversation-item-selected', conversation.isPinned && 'tui-conversation-item-pinned'
conversation.isPinned && 'tui-conversation-item-pinned',
]" ]"
@click="enterConversationChat(conversation.conversationID)" @click="enterConversationChat(conversation.conversationID)"
@longpress="showConversationActionMenu($event, conversation, index)" @longpress="showConversationActionMenu($event, conversation, index)"
@ -42,22 +38,17 @@
:class="[ :class="[
'online-status', 'online-status',
Object.keys(userOnlineStatusMap).length > 0 && Object.keys(userOnlineStatusMap).length > 0 &&
Object.keys(userOnlineStatusMap).includes( Object.keys(userOnlineStatusMap).includes(conversation.userProfile.userID) &&
conversation.userProfile.userID userOnlineStatusMap[conversation.userProfile.userID].statusType === 1
) &&
userOnlineStatusMap[conversation.userProfile.userID]
.statusType === 1
? 'online-status-online' ? 'online-status-online'
: 'online-status-offline', : 'online-status-offline'
]" ]"
/> />
<span <span
v-if="conversation.unreadCount > 0 && !conversation.isMuted" v-if="conversation.unreadCount > 0 && !conversation.isMuted"
class="num" class="num"
> >
{{ {{ conversation.unreadCount > 99 ? '99+' : conversation.unreadCount }}
conversation.unreadCount > 99 ? "99+" : conversation.unreadCount
}}
</span> </span>
<span <span
v-if="conversation.unreadCount > 0 && conversation.isMuted" v-if="conversation.unreadCount > 0 && conversation.isMuted"
@ -73,22 +64,22 @@
<span <span
v-if="conversation.draftText && conversation.conversationID !== currentConversationID" v-if="conversation.draftText && conversation.conversationID !== currentConversationID"
class="middle-box-draft" class="middle-box-draft"
>{{ TUITranslateService.t('TUIChat.[草稿]') }}</span> >
{{ TUITranslateService.t('TUIChat.[草稿]') }}
</span>
<span <span
v-else-if=" v-else-if="conversation.type === 'GROUP' && conversation.groupAtInfoList && conversation.groupAtInfoList.length > 0"
conversation.type === 'GROUP' &&
conversation.groupAtInfoList &&
conversation.groupAtInfoList.length > 0
"
class="middle-box-at" class="middle-box-at"
>{{ conversation.getGroupAtInfo() }}</span> >
{{ conversation.getGroupAtInfo() }}
</span>
<div class="middle-box-content"> <div class="middle-box-content">
{{ conversation.getLastMessage("text") }} {{ conversation.getLastMessage('text') }}
</div> </div>
</div> </div>
</div> </div>
<div class="content-footer"> <div class="content-footer">
<span class="time">{{ conversation.getLastMessage("time") }}</span> <span class="time">{{ conversation.getLastMessage('time') }}</span>
<Icon <Icon
v-if="conversation.isMuted" v-if="conversation.isMuted"
:file="muteIcon" :file="muteIcon"
@ -111,13 +102,7 @@ interface IUserStatusMap {
} }
import { ref, onMounted, onUnmounted } from '../../../adapter-vue'; import { ref, onMounted, onUnmounted } from '../../../adapter-vue';
import TUIChatEngine, { import TUIChatEngine, { TUIStore, StoreName, TUIConversationService, TUITranslateService, IConversationModel } from '@tencentcloud/chat-uikit-engine';
TUIStore,
StoreName,
TUIConversationService,
TUITranslateService,
IConversationModel,
} from '@tencentcloud/chat-uikit-engine';
import { TUIGlobal, isIOS, addLongPressListener } from '@tencentcloud/universal-api'; import { TUIGlobal, isIOS, addLongPressListener } from '@tencentcloud/universal-api';
import Icon from '../../common/Icon.vue'; import Icon from '../../common/Icon.vue';
import Avatar from '../../common/Avatar/index.vue'; import Avatar from '../../common/Avatar/index.vue';
@ -140,7 +125,7 @@ const actionsMenuPosition = ref<{
}>({ }>({
top: 0, top: 0,
left: undefined, left: undefined,
conversationHeight: undefined, conversationHeight: undefined
}); });
const displayOnlineStatus = ref(false); const displayOnlineStatus = ref(false);
const userOnlineStatusMap = ref<IUserStatusMap>(); const userOnlineStatusMap = ref<IUserStatusMap>();
@ -148,16 +133,15 @@ const userOnlineStatusMap = ref<IUserStatusMap>();
let lastestOpenActionsMenuTime: number | null = null; let lastestOpenActionsMenuTime: number | null = null;
onMounted(() => { onMounted(() => {
console.log(conversationList)
TUIStore.watch(StoreName.CONV, { TUIStore.watch(StoreName.CONV, {
currentConversationID: onCurrentConversationIDUpdated, currentConversationID: onCurrentConversationIDUpdated,
conversationList: onConversationListUpdated, conversationList: onConversationListUpdated,
currentConversation: onCurrentConversationUpdated, currentConversation: onCurrentConversationUpdated
}); });
TUIStore.watch(StoreName.USER, { TUIStore.watch(StoreName.USER, {
displayOnlineStatus: onDisplayOnlineStatusUpdated, displayOnlineStatus: onDisplayOnlineStatusUpdated,
userStatusList: onUserStatusListUpdated, userStatusList: onUserStatusListUpdated
}); });
if (!isUniFrameWork && isIOS && !isPC) { if (!isUniFrameWork && isIOS && !isPC) {
@ -169,28 +153,20 @@ onUnmounted(() => {
TUIStore.unwatch(StoreName.CONV, { TUIStore.unwatch(StoreName.CONV, {
currentConversationID: onCurrentConversationIDUpdated, currentConversationID: onCurrentConversationIDUpdated,
conversationList: onConversationListUpdated, conversationList: onConversationListUpdated,
currentConversation: onCurrentConversationUpdated, currentConversation: onCurrentConversationUpdated
}); });
TUIStore.unwatch(StoreName.USER, { TUIStore.unwatch(StoreName.USER, {
displayOnlineStatus: onDisplayOnlineStatusUpdated, displayOnlineStatus: onDisplayOnlineStatusUpdated,
userStatusList: onUserStatusListUpdated, userStatusList: onUserStatusListUpdated
}); });
}); });
const isShowUserOnlineStatus = (conversation: IConversationModel): boolean => { const isShowUserOnlineStatus = (conversation: IConversationModel): boolean => {
return ( return displayOnlineStatus.value && conversation.type === TUIChatEngine.TYPES.CONV_C2C;
displayOnlineStatus.value
&& conversation.type === TUIChatEngine.TYPES.CONV_C2C
);
}; };
const showConversationActionMenu = ( const showConversationActionMenu = (event: Event, conversation: IConversationModel, index: number, isContextMenuEvent?: boolean) => {
event: Event,
conversation: IConversationModel,
index: number,
isContextMenuEvent?: boolean,
) => {
if (isContextMenuEvent) { if (isContextMenuEvent) {
event.preventDefault(); event.preventDefault();
if (isUniFrameWork) { if (isUniFrameWork) {
@ -204,10 +180,7 @@ const showConversationActionMenu = (
const closeConversationActionMenu = () => { const closeConversationActionMenu = () => {
// Prevent continuous triggering of overlay tap events // Prevent continuous triggering of overlay tap events
if ( if (lastestOpenActionsMenuTime && Date.now() - lastestOpenActionsMenuTime > 300) {
lastestOpenActionsMenuTime
&& Date.now() - lastestOpenActionsMenuTime > 300
) {
currentConversation.value = undefined; currentConversation.value = undefined;
isShowOverlay.value = false; isShowOverlay.value = false;
} }
@ -219,25 +192,28 @@ const getActionsMenuPosition = (event: Event, index: number) => {
emits('getPassingRef', conversationListDomRef); emits('getPassingRef', conversationListDomRef);
} }
const query = TUIGlobal?.createSelectorQuery().in(conversationListDomRef.value); const query = TUIGlobal?.createSelectorQuery().in(conversationListDomRef.value);
query.select(`#convlistitem-${index}`).boundingClientRect((data) => { query
.select(`#convlistitem-${index}`)
.boundingClientRect((data) => {
if (data) { if (data) {
actionsMenuPosition.value = { actionsMenuPosition.value = {
// The uni-page-head of uni-h5 is not considered a member of the viewport, so the height of the head is manually increased. // The uni-page-head of uni-h5 is not considered a member of the viewport, so the height of the head is manually increased.
top: data.bottom + (isH5 ? 44 : 0), top: data.bottom + (isH5 ? 44 : 0),
// @ts-expect-error in uniapp event has touches property // @ts-expect-error in uniapp event has touches property
left: event.touches[0].pageX, left: event.touches[0].pageX,
conversationHeight: data.height, conversationHeight: data.height
}; };
isShowOverlay.value = true; isShowOverlay.value = true;
} }
}).exec(); })
.exec();
} else { } else {
const rect = ((event.currentTarget || event.target) as HTMLElement)?.getBoundingClientRect() || {}; const rect = ((event.currentTarget || event.target) as HTMLElement)?.getBoundingClientRect() || {};
if (rect) { if (rect) {
actionsMenuPosition.value = { actionsMenuPosition.value = {
top: rect.bottom, top: rect.bottom,
left: isPC ? (event as MouseEvent).clientX : undefined, left: isPC ? (event as MouseEvent).clientX : undefined,
conversationHeight: rect.height, conversationHeight: rect.height
}; };
} }
isShowOverlay.value = true; isShowOverlay.value = true;
@ -261,9 +237,9 @@ function addLongPressHandler() {
}, },
options: { options: {
eventDelegation: { eventDelegation: {
subSelector: '.tui-conversation-content', subSelector: '.tui-conversation-content'
}, }
}, }
}); });
} }
@ -273,6 +249,8 @@ function onCurrentConversationUpdated(conversation: IConversationModel) {
function onConversationListUpdated(list: IConversationModel[]) { function onConversationListUpdated(list: IConversationModel[]) {
conversationList.value = list; conversationList.value = list;
console.log('会话列表数据', conversationList.value);
console.log('Conversation实例:', TUIStore);
} }
function onCurrentConversationIDUpdated(id: string) { function onCurrentConversationIDUpdated(id: string) {
@ -285,13 +263,10 @@ function onDisplayOnlineStatusUpdated(status: boolean) {
function onUserStatusListUpdated(list: Map<string, IUserStatus>) { function onUserStatusListUpdated(list: Map<string, IUserStatus>) {
if (list.size !== 0) { if (list.size !== 0) {
userOnlineStatusMap.value = [...list.entries()].reduce( userOnlineStatusMap.value = [...list.entries()].reduce((obj, [key, value]) => {
(obj, [key, value]) => {
obj[key] = value; obj[key] = value;
return obj; return obj;
}, }, {} as IUserStatusMap);
{} as IUserStatusMap,
);
} }
} }
// Expose to the parent component and close actionsMenu when a sliding event is detected // Expose to the parent component and close actionsMenu when a sliding event is detected

35
api/checkInfo.js Normal file
View File

@ -0,0 +1,35 @@
/**
* @description 文本内容审核
* AuditName:1600080789_1745821176_amtwGf
* ContentType:Text|Image|Audio|Video
* Content:需要审核的文本内容
* ExtSender:im的id这里对应的是用户手机号
* ExtReceiver:接收方的信息选填
*/
import {
http,
Method
} from "@/utils/request.js";
export function checkText({
ExtSender,
Content,
}) {
return http.request({
url: 'https://console.tim.qq.com/v4/im_msg_audit/content_moderation'
method: Method.POST,
params: {
sdkappid: '1600080789',
identifier: 'administrator',
usersig: 'eJwtjEELgjAYhv-LroV9zi2n0CU6VBSRJV28jLbiK7SxjRxE-z1Tj*-zvDwfct6dore2JCc0AjLtNyrdeLxhj6WqsUHnrfQvOx6cekpjUJE8ngOAgFRkg9HBoNUd55zTTg3UY-1nKeOCJomIxwreu76BMnv4TcGXZTVrgMVMFm6795NQH8OateqK7CBbu7oYWJDvD4AYNPU_',
random: Math.floor(Math.random() * (4294967295 + 1)),
contenttype: 'json'
},
data: {
AuditName: '1600080789_1745821176_amtwGf'
ContentType: 'Text',
Content,
ExtSender
}
});
}

View File

@ -192,7 +192,7 @@
<!-- 4.分享 --> <!-- 4.分享 -->
<view <view
v-if="item.isShowProgressBarTime == false" v-if="item.isShowProgressBarTime == false"
@click="share" @click="share(item)"
style="opacity: 0.9; margin-top: 17px" style="opacity: 0.9; margin-top: 17px"
> >
<image <image
@ -415,6 +415,7 @@
:thisVlogId="pinglunInfo.vlogId" :thisVlogId="pinglunInfo.vlogId"
:vlogUrl="pinglunInfo.url" :vlogUrl="pinglunInfo.url"
:isPrivate="pinglunInfo.isPrivate" :isPrivate="pinglunInfo.isPrivate"
:vlogItem="pinglunInfo"
></uni-popup-share> ></uni-popup-share>
</uni-popup> </uni-popup>
</view> </view>
@ -984,6 +985,7 @@ export default {
}, 50); }, 50);
} else { } else {
this.noData = '暂无数据'; this.noData = '暂无数据';
this.isShow1 = false;
} }
} else { } else {
uni.showToast({ uni.showToast({
@ -1103,7 +1105,8 @@ export default {
animation: true animation: true
}); });
}, },
share() { share(item) {
this.pinglunInfo = item;
this.$refs.share.open(); this.$refs.share.open();
uni.hideTabBar({ uni.hideTabBar({
animation: true animation: true

View File

@ -192,7 +192,7 @@
<!-- 4.分享 --> <!-- 4.分享 -->
<view <view
v-if="item.isShowProgressBarTime == false" v-if="item.isShowProgressBarTime == false"
@click="share" @click="share(item)"
style="opacity: 0.9; margin-top: 17px" style="opacity: 0.9; margin-top: 17px"
> >
<image <image
@ -415,6 +415,7 @@
:thisVlogId="pinglunInfo.vlogId" :thisVlogId="pinglunInfo.vlogId"
:vlogUrl="pinglunInfo.url" :vlogUrl="pinglunInfo.url"
:isPrivate="pinglunInfo.isPrivate" :isPrivate="pinglunInfo.isPrivate"
:vlogItem="pinglunInfo"
></uni-popup-share> ></uni-popup-share>
</uni-popup> </uni-popup>
</view> </view>
@ -985,6 +986,7 @@ export default {
}, 50); }, 50);
} else { } else {
this.noData = '暂无数据'; this.noData = '暂无数据';
this.isShow1 = false;
return; return;
} }
} else { } else {
@ -1105,7 +1107,8 @@ export default {
animation: true animation: true
}); });
}, },
share() { share(item) {
this.pinglunInfo = item;
this.$refs.share.open(); this.$refs.share.open();
uni.hideTabBar({ uni.hideTabBar({
animation: true animation: true

View File

@ -185,7 +185,7 @@
<!-- 4.分享 --> <!-- 4.分享 -->
<view <view
v-if="item.isShowProgressBarTime == false" v-if="item.isShowProgressBarTime == false"
@click="share" @click="share(item)"
style="opacity: 0.9; margin-top: 17px" style="opacity: 0.9; margin-top: 17px"
> >
<image <image
@ -408,6 +408,7 @@
:thisVlogId="pinglunInfo.vlogId" :thisVlogId="pinglunInfo.vlogId"
:vlogUrl="pinglunInfo.url" :vlogUrl="pinglunInfo.url"
:isPrivate="pinglunInfo.isPrivate" :isPrivate="pinglunInfo.isPrivate"
:vlogItem="pinglunInfo"
></uni-popup-share> ></uni-popup-share>
</uni-popup> </uni-popup>
</view> </view>
@ -1087,7 +1088,8 @@ export default {
animation: true animation: true
}); });
}, },
share() { share(item) {
this.pinglunInfo = item;
this.$refs.share.open(); this.$refs.share.open();
uni.hideTabBar({ uni.hideTabBar({
animation: true animation: true

View File

@ -17,7 +17,7 @@ const prod = {
// buyer: "https://buyer-api.pickmall.cn", // buyer: "https://buyer-api.pickmall.cn",
common: "http://192.168.1.211:8890", common: "http://192.168.1.211:8890",
buyer: "http://192.168.1.211:8888", buyer: "http://192.168.1.211:8888",
vlog: "http://192.168.1.86:8099", vlog: "http://192.168.1.211:8099",
}; };
//默认生产环境 //默认生产环境

View File

@ -270,7 +270,7 @@ export default {
onShow() { onShow() {
let me = this; let me = this;
// 判断我有没有登录 // 判断我有没有登录
this.userIsLogin = filters.isLogin('auth'); this.userIsLogin = storage.getHasLogin();
console.log(this.userIsLogin); console.log(this.userIsLogin);
if (this.userIsLogin) { if (this.userIsLogin) {
this.getUinfo(); this.getUinfo();
@ -280,9 +280,9 @@ export default {
}, },
onTabItemTap: (e) => { onTabItemTap: (e) => {
console.log(e); console.log(e);
if (!filters.isLogin('auth')) { if (!storage.getHasLogin()) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/passport/login?init=index' url: '/pages/passport/login'
}); });
} }
}, },

View File

@ -195,7 +195,7 @@
<!-- 4.分享 --> <!-- 4.分享 -->
<view <view
v-if="item.isShowProgressBarTime == false" v-if="item.isShowProgressBarTime == false"
@click="share" @click="share(item)"
style="opacity: 0.9; margin-top: 17px" style="opacity: 0.9; margin-top: 17px"
> >
<image <image
@ -418,6 +418,7 @@
:thisVlogId="pinglunInfo.vlogId" :thisVlogId="pinglunInfo.vlogId"
:vlogUrl="pinglunInfo.url" :vlogUrl="pinglunInfo.url"
:isPrivate="pinglunInfo.isPrivate" :isPrivate="pinglunInfo.isPrivate"
:vlogItem="pinglunInfo"
></uni-popup-share> ></uni-popup-share>
</uni-popup> </uni-popup>
</view> </view>
@ -1123,7 +1124,8 @@ export default {
animation: true animation: true
}); });
}, },
share() { share(item) {
this.pinglunInfo = item;
this.$refs.share.open(); this.$refs.share.open();
uni.hideTabBar({ uni.hideTabBar({
animation: true animation: true

View File

@ -1,29 +1,63 @@
<template> <template>
<view class="person-msg"> <view class="person-msg">
<view class="head c-content" @click="changeFace"> <view
<image :src="form.face || '/static/missing-face.png'" mode=""></image> class="head c-content"
@click="changeFace"
>
<image
:src="form.face || '/static/missing-face.png'"
mode=""
></image>
<view>点击修改头像</view> <view>点击修改头像</view>
</view> </view>
<u-form :model="form" ref="uForm" class="form"> <u-form
<u-form-item label="昵称" label-width="150"> :model="form"
ref="uForm"
class="form"
>
<u-form-item
label="昵称"
label-width="150"
>
<u-input <u-input
v-model="form.nickName" v-model="form.nickName"
placeholder="请输入昵称" placeholder="请输入昵称"
maxlength="10" maxlength="10"
/> />
</u-form-item> </u-form-item>
<u-form-item label="二维码" label-width="150"> <u-form-item
<img :src="erwei" alt="" width="60" @click="showQrCodeInFullSize" /> label="二维码"
label-width="150"
>
<img
:src="erwei"
alt=""
width="60"
@click="showQrCodeInFullSize"
/>
</u-form-item> </u-form-item>
<u-form-item label="性别" label-width="150"> <u-form-item
<u-radio-group v-model="form.sex" :active-color="lightColor"> label="性别"
label-width="150"
>
<u-radio-group
v-model="form.sex"
:active-color="lightColor"
>
<u-radio name="1"></u-radio> <u-radio name="1"></u-radio>
<u-radio name="0"></u-radio> <u-radio name="0"></u-radio>
</u-radio-group> </u-radio-group>
</u-form-item> </u-form-item>
<u-form-item label="生日" label-width="150" right-icon="arrow-right"> <u-form-item
<div style="width: 100%" @click="showBirthday = true"> label="生日"
{{ birthday || "请选择出生日期" }} label-width="150"
right-icon="arrow-right"
>
<div
style="width: 100%"
@click="showBirthday = true"
>
{{ birthday || '请选择出生日期' }}
</div> </div>
<u-picker <u-picker
v-model="showBirthday" v-model="showBirthday"
@ -40,22 +74,27 @@
right-icon="arrow-right" right-icon="arrow-right"
> >
<div <div
style=" style="width: 32vh; white-space: nowrap; overflow: hidden; text-overflow: ellipsis"
width: 32vh;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
"
@click="clickRegion" @click="clickRegion"
> >
{{ form.___path || "请选择城市" }} {{ form.___path || '请选择城市' }}
</div> </div>
</u-form-item> </u-form-item>
</u-form> </u-form>
<div style="display: flex; justify-content: center"></div> <div style="display: flex; justify-content: center"></div>
<div class="bottom"> <div class="bottom">
<view class="submit" @click="submit">保存</view> <view
<view class="submit light" @click="showModalDialog">退出登录</view> class="submit"
@click="submit"
>
保存
</view>
<view
class="submit light"
@click="showModalDialog"
>
退出登录
</view>
</div> </div>
<u-modal <u-modal
show-cancel-button show-cancel-button
@ -75,52 +114,53 @@
</view> </view>
</template> </template>
<script> <script>
import { saveUserInfo, geterwei } from "@/api/members.js"; import { saveUserInfo, geterwei } from '@/api/members.js';
import { upload } from "@/api/common.js"; import { upload } from '@/api/common.js';
import { logout } from "@/api/login"; import { logout } from '@/api/login';
import storage from "@/utils/storage.js"; import storage from '@/utils/storage.js';
import uFormItem from "@/uview-ui/components/u-form-item/u-form-item.vue"; import uFormItem from '@/uview-ui/components/u-form-item/u-form-item.vue';
import gkcity from "@/components/m-city/m-city.vue"; import gkcity from '@/components/m-city/m-city.vue';
import { clearIm } from '@/utils/handleim.js';
export default { export default {
components: { components: {
uFormItem, uFormItem,
"m-city": gkcity, 'm-city': gkcity
}, },
data() { data() {
return { return {
erwei: "", erwei: '',
quitShow: false, quitShow: false,
userInfo: {}, userInfo: {},
lightColor: this.$lightColor, // lightColor: this.$lightColor, //
form: { form: {
nickName: storage.getUserInfo().nickName || "", nickName: storage.getUserInfo().nickName || '',
birthday: storage.getUserInfo().birthday || "", birthday: storage.getUserInfo().birthday || '',
face: storage.getUserInfo().face || "/static/imlogo.png", // face: storage.getUserInfo().face || '/static/imlogo.png', //
regionId: [], //Id regionId: [], //Id
region: storage.getUserInfo().region || [], // region: storage.getUserInfo().region || [], //
sex: storage.getUserInfo().sex, // sex: storage.getUserInfo().sex, //
___path: storage.getUserInfo().region, ___path: storage.getUserInfo().region
}, },
birthday: storage.getUserInfo().birthday || "", // birthday: storage.getUserInfo().birthday || '', //
photo: [ photo: [
{ {
text: "立即拍照", text: '立即拍照',
color: this.$mainColor, color: this.$mainColor
}, },
{ {
text: "从相册选择", text: '从相册选择',
color: this.$mainColor, color: this.$mainColor
}, }
], ],
region: [ region: [
// //
{ {
id: "", id: '',
localName: "请选择", localName: '请选择',
children: [], children: []
}, }
], ],
showBirthday: false, // showBirthday: false //
}; };
}, },
onShow() { onShow() {
@ -131,7 +171,7 @@ export default {
showQrCodeInFullSize() { showQrCodeInFullSize() {
uni.previewImage({ uni.previewImage({
urls: [this.erwei], urls: [this.erwei],
current: this.erwei, current: this.erwei
}); });
}, },
getgeterwei() { getgeterwei() {
@ -143,13 +183,20 @@ export default {
this.quitShow = true; this.quitShow = true;
}, },
clear() { clear() {
storage.setAccessToken(""); storage.setRefreshVlogIndex('1'); //
storage.setRefreshToken(""); storage.setHasLogin(false);
storage.setAccessToken('');
storage.setRefreshToken('');
storage.setUuid('');
storage.setUserInfo({}); storage.setUserInfo({});
// vlog // vlog
storage.setVlogToken(""); storage.setVlogToken('');
storage.setVlogUserInfo({}); storage.setVlogUserInfo(null);
this.$options.filters.navigateToLogin("redirectTo"); //
storage.setRefreshVlogIndex('1'); //
// 退im
clearIm();
this.$options.filters.navigateToLogin('redirectTo');
}, },
/** /**
* 确认退出 * 确认退出
@ -171,7 +218,7 @@ export default {
getpickerParentValue(e) { getpickerParentValue(e) {
this.form.region = []; this.form.region = [];
this.form.regionId = []; this.form.regionId = [];
let name = ""; let name = '';
e.forEach((item, index) => { e.forEach((item, index) => {
if (item.id) { if (item.id) {
@ -180,7 +227,7 @@ export default {
if (index == e.length - 1) { if (index == e.length - 1) {
name += item.localName; name += item.localName;
} else { } else {
name += item.localName + ","; name += item.localName + ',';
} }
this.form.___path = name; this.form.___path = name;
} }
@ -218,16 +265,16 @@ export default {
uni.uploadFile({ uni.uploadFile({
url: upload, url: upload,
filePath: tempFilePaths[0], filePath: tempFilePaths[0],
name: "file", name: 'file',
header: { header: {
accessToken: storage.getAccessToken(), accessToken: storage.getAccessToken()
}, },
success: (uploadFileRes) => { success: (uploadFileRes) => {
let data = JSON.parse(uploadFileRes.data); let data = JSON.parse(uploadFileRes.data);
this.form.face = data.result; this.form.face = data.result;
}, }
}); });
}, }
}); });
}, },
@ -235,11 +282,7 @@ export default {
* 选择地址 * 选择地址
*/ */
selectRegion(region) { selectRegion(region) {
this.$set( this.$set(this.form, 'address', `${region.province.label} ${region.city.label} ${region.area.label}`);
this.form,
"address",
`${region.province.label} ${region.city.label} ${region.area.label}`
);
}, },
/** /**
@ -248,13 +291,13 @@ export default {
selectTime(time) { selectTime(time) {
this.form.birthday = `${time.year}-${time.month}-${time.day}`; this.form.birthday = `${time.year}-${time.month}-${time.day}`;
this.birthday = `${time.year} - ${time.month} - ${time.day}`; this.birthday = `${time.year} - ${time.month} - ${time.day}`;
}, }
}, },
/** /**
* 加载数据 * 加载数据
*/ */
onLoad() {}, onLoad() {}
}; };
</script> </script>

View File

@ -1,37 +1,72 @@
<template> <template>
<view class="container"> <view class="container">
<view class="person" @click="checkUserInfo()"> <view
<u-image width=140 height="140" shape="circle" :src="userInfo.face || '/static/missing-face.png'" mode=""> class="person"
</u-image> @click="checkUserInfo()"
>
<u-image
width="140"
height="140"
shape="circle"
:src="userInfo.face || '/static/missing-face.png'"
mode=""
></u-image>
<view class="user-name"> <view class="user-name">
{{ userInfo.id ? userInfo.nickName || '' : '暂未登录' }} {{ userInfo.id ? userInfo.nickName || '' : '暂未登录' }}
</view> </view>
<u-icon color="#ccc" name="arrow-right"></u-icon> <u-icon
color="#ccc"
name="arrow-right"
></u-icon>
</view> </view>
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<view style="height: 20rpx; width: 100%"></view> <view style="height: 20rpx; width: 100%"></view>
<!-- #endif --> <!-- #endif -->
<u-cell-group :border="false"> <u-cell-group :border="false">
<!-- #ifdef APP-PLUS --> <!-- #ifdef APP-PLUS -->
<u-cell-item title="清除缓存" :value="fileSizeString" @click="clearCache"></u-cell-item> <u-cell-item
title="清除缓存"
:value="fileSizeString"
@click="clearCache"
></u-cell-item>
<!-- #endif --> <!-- #endif -->
<u-cell-item title="安全中心" @click="navigateTo('/pages/mine/set/securityCenter/securityCenter')"></u-cell-item> <u-cell-item
<u-cell-item title="意见反馈" @click="navigateTo('/pages/mine/set/feedBack')"></u-cell-item> title="安全中心"
@click="navigateTo('/pages/mine/set/securityCenter/securityCenter')"
></u-cell-item>
<u-cell-item
title="意见反馈"
@click="navigateTo('/pages/mine/set/feedBack')"
></u-cell-item>
<!-- #ifndef H5 --> <!-- #ifndef H5 -->
<!-- #endif --> <!-- #endif -->
<u-cell-item :title="`关于我们`" @click="navigateTo('/pages/mine/set/editionIntro')"></u-cell-item> <u-cell-item
:title="`关于我们`"
@click="navigateTo('/pages/mine/set/editionIntro')"
></u-cell-item>
</u-cell-group> </u-cell-group>
<view class="submit" @click="showModalDialog">{{userInfo.id ?'退出登录':'返回登录'}}</view> <view
<u-modal show-cancel-button v-model="quitShow" @confirm="confirm" :confirm-color="lightColor" :async-close="true" class="submit"
:content="userInfo.id ? '确定要退出登录么?' : '确定要返回登录么?'"></u-modal> @click="showModalDialog"
>
{{ userInfo.id ? '退出登录' : '返回登录' }}
</view>
<u-modal
show-cancel-button
v-model="quitShow"
@confirm="confirm"
:confirm-color="lightColor"
:async-close="true"
:content="userInfo.id ? '确定要退出登录么?' : '确定要返回登录么?'"
></u-modal>
</view> </view>
</template> </template>
<script> <script>
import { logout } from "@/api/login"; import { logout } from '@/api/login';
import storage from "@/utils/storage.js"; import storage from '@/utils/storage.js';
import config from "@/config/config"; import config from '@/config/config';
import { clearIm } from '@/utils/handleim.js';
export default { export default {
data() { data() {
return { return {
@ -40,27 +75,34 @@ export default {
quitShow: false, quitShow: false,
isCertificate: false, isCertificate: false,
userInfo: {}, userInfo: {},
fileSizeString: "0B", fileSizeString: '0B'
}; };
}, },
methods: { methods: {
navigateTo(url) { navigateTo(url) {
if (url == "/pages/set/securityCenter/securityCenter") { if (url == '/pages/set/securityCenter/securityCenter') {
url += `?mobile=${this.userInfo.mobile}`; url += `?mobile=${this.userInfo.mobile}`;
} }
uni.navigateTo({ uni.navigateTo({
url: url, url: url
}); });
}, },
clear() { clear() {
storage.setAccessToken(""); storage.setRefreshVlogIndex('1'); //
storage.setRefreshToken(""); storage.setHasLogin(false);
storage.setAccessToken('');
storage.setRefreshToken('');
storage.setUuid('');
storage.setUserInfo({}); storage.setUserInfo({});
// vlog // vlog
storage.setVlogToken("") storage.setVlogToken('');
storage.setVlogUserInfo({}) storage.setVlogUserInfo(null);
this.$options.filters.navigateToLogin("redirectTo"); //
storage.setRefreshVlogIndex('1'); //
// 退im
clearIm();
this.$options.filters.navigateToLogin('redirectTo');
}, },
/** /**
@ -88,15 +130,15 @@ export default {
plus.cache.calculate(function (size) { plus.cache.calculate(function (size) {
let sizeCache = parseInt(size); let sizeCache = parseInt(size);
if (sizeCache == 0) { if (sizeCache == 0) {
that.fileSizeString = "0B"; that.fileSizeString = '0B';
} else if (sizeCache < 1024) { } else if (sizeCache < 1024) {
that.fileSizeString = sizeCache + "B"; that.fileSizeString = sizeCache + 'B';
} else if (sizeCache < 1048576) { } else if (sizeCache < 1048576) {
that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB"; that.fileSizeString = (sizeCache / 1024).toFixed(2) + 'KB';
} else if (sizeCache < 1073741824) { } else if (sizeCache < 1073741824) {
that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB"; that.fileSizeString = (sizeCache / 1048576).toFixed(2) + 'MB';
} else { } else {
that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB"; that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + 'GB';
} }
}); });
}, },
@ -106,13 +148,13 @@ export default {
* 判断当前是否进入用户中心 * 判断当前是否进入用户中心
*/ */
checkUserInfo() { checkUserInfo() {
if (this.$options.filters.isLogin("auth")) { if (this.$options.filters.isLogin('auth')) {
this.navigateTo("/pages/mine/set/personMsg"); this.navigateTo('/pages/mine/set/personMsg');
} else { } else {
uni.showToast({ uni.showToast({
title: "当前暂无用户请登录后重试", title: '当前暂无用户请登录后重试',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
} }
}, },
@ -124,13 +166,13 @@ export default {
// //
let that = this; let that = this;
let os = plus.os.name; let os = plus.os.name;
if (os == "Android") { if (os == 'Android') {
let main = plus.android.runtimeMainActivity(); let main = plus.android.runtimeMainActivity();
let sdRoot = main.getCacheDir(); let sdRoot = main.getCacheDir();
let files = plus.android.invoke(sdRoot, "listFiles"); let files = plus.android.invoke(sdRoot, 'listFiles');
let len = files.length; let len = files.length;
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
let filePath = "" + files[i]; // let filePath = '' + files[i]; //
plus.io.resolveLocalFileSystemURL( plus.io.resolveLocalFileSystemURL(
filePath, filePath,
function (entry) { function (entry) {
@ -139,9 +181,9 @@ export default {
function (entry) { function (entry) {
// //
uni.showToast({ uni.showToast({
title: "缓存清理完成", title: '缓存清理完成',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
that.getCacheSize(); // that.getCacheSize(); //
}, },
@ -153,9 +195,9 @@ export default {
}, },
function (e) { function (e) {
uni.showToast({ uni.showToast({
title: "文件路径读取失败", title: '文件路径读取失败',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
} }
); );
@ -164,25 +206,25 @@ export default {
// ios // ios
plus.cache.clear(function () { plus.cache.clear(function () {
uni.showToast({ uni.showToast({
title: "缓存清理完成", title: '缓存清理完成',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
that.getCacheSize(); that.getCacheSize();
}); });
} }
}, }
}, },
onShow() { onShow() {
this.userInfo = this.$options.filters.isLogin(); this.userInfo = this.$options.filters.isLogin();
// #ifdef APP-PLUS // #ifdef APP-PLUS
this.getCacheSize(); this.getCacheSize();
// #endif // #endif
}, }
}; };
</script> </script>
<style lang='scss' scoped> <style lang="scss" scoped>
.submit { .submit {
height: 90rpx; height: 90rpx;
line-height: 90rpx; line-height: 90rpx;

View File

@ -11,7 +11,10 @@
</div> --> </div> -->
</div> </div>
<!-- 手机号 --> <!-- 手机号 -->
<div v-show="current == 0" style="padding: 0px 40px"> <div
v-show="current == 0"
style="padding: 0px 40px"
>
<u-input <u-input
:custom-style="inputStyle" :custom-style="inputStyle"
:placeholder-style="placeholderStyle" :placeholder-style="placeholderStyle"
@ -30,7 +33,10 @@
获取验证码 获取验证码
</div> </div>
<div class="flex"> <div class="flex">
<u-checkbox-group :icon-size="24" width="45rpx"> <u-checkbox-group
:icon-size="24"
width="45rpx"
>
<u-checkbox <u-checkbox
shape="circle" shape="circle"
v-model="enabulePrivacy" v-model="enabulePrivacy"
@ -38,15 +44,16 @@
></u-checkbox> ></u-checkbox>
</u-checkbox-group> </u-checkbox-group>
<div class="tips"> <div class="tips">
未注册的手机号验证后将自动创建用户账号登录即代表您已同意<span 未注册的手机号验证后将自动创建用户账号登录即代表您已同意
@click="navigateToPrivacy('privacy')" <span @click="navigateToPrivacy('privacy')">使用条款及隐私协议</span>
>使用条款及隐私协议</span
>
</div> </div>
</div> </div>
</div> </div>
<!-- 输入验证码 --> <!-- 输入验证码 -->
<div v-show="current == 1" class="box-code"> <div
v-show="current == 1"
class="box-code"
>
<verifyCode <verifyCode
type="bottom" type="bottom"
@confirm="submit" @confirm="submit"
@ -68,9 +75,12 @@
ref="uCode" ref="uCode"
@change="codeChange" @change="codeChange"
></u-verification-code> ></u-verification-code>
<span @tap="fetchCode" :style="{ color: codeColor }"> <span
{{ tips }}</span @tap="fetchCode"
:style="{ color: codeColor }"
> >
{{ tips }}
</span>
</div> </div>
</div> </div>
@ -116,22 +126,23 @@
</template> </template>
<script> <script>
import { openIdLogin, loginCallback } from "@/api/connect.js"; import { openIdLogin, loginCallback } from '@/api/connect.js';
import api from "@/config/api.js"; import api from '@/config/api.js';
import { sendMobile, smsLogin } from "@/api/login"; import { sendMobile, smsLogin } from '@/api/login';
import myVerification from "@/components/verification/verification.vue"; // import myVerification from '@/components/verification/verification.vue'; //
import uuid from "@/utils/uuid.modified.js"; // uuid import uuid from '@/utils/uuid.modified.js'; // uuid
import verifyCode from "@/components/verify-code/verify-code"; import verifyCode from '@/components/verify-code/verify-code';
import { getUserInfo } from "@/api/members"; import { getUserInfo } from '@/api/members';
import { whetherNavigate } from "@/utils/Foundation"; // import { whetherNavigate } from '@/utils/Foundation'; //
import storage from "@/utils/storage.js"; // import storage from '@/utils/storage.js'; //
import wechatH5Login from "./wechatH5Login.vue"; import wechatH5Login from './wechatH5Login.vue';
import { webConnect } from "@/api/connect.js"; import { webConnect } from '@/api/connect.js';
import { loginIm } from '@/utils/handleim.js';
export default { export default {
components: { components: {
myVerification, myVerification,
verifyCode, verifyCode,
wechatH5Login, wechatH5Login
}, },
data() { data() {
@ -140,57 +151,57 @@ export default {
wechatLogin: false, // wechatLogin: false, //
flage: false, // flage: false, //
codeFlag: true, // codeFlag: true, //
tips: "", tips: '',
current: 0, current: 0,
codeColor: "#999", // codeColor: '#999', //
lightColor: this.$lightColor, lightColor: this.$lightColor,
seconds: 60, // seconds: 60, //
loginTitleWay: [ loginTitleWay: [
{ {
title: "欢迎登录", title: '欢迎登录',
desc: "登录后更精彩,美好生活即将开始", desc: '登录后更精彩,美好生活即将开始'
}, },
{ {
title: "请输入验证码", title: '请输入验证码',
desc: "已经发送验证码至", desc: '已经发送验证码至'
}, }
], ],
showBack: false, showBack: false,
enabuleFetchCode: false, enabuleFetchCode: false,
enabulePrivacy: false, // enabulePrivacy: false, //
mobile: "", // mobile: '', //
code: "", // code: '', //
inputStyle: { inputStyle: {
height: "104rpx", height: '104rpx',
"border-bottom": "1rpx solid #D8D8D8", 'border-bottom': '1rpx solid #D8D8D8',
"letter-spacing": "1rpx", 'letter-spacing': '1rpx',
"font-size": "40rpx", 'font-size': '40rpx',
"line-height": "40rpx", 'line-height': '40rpx',
color: "#333", color: '#333'
}, },
placeholderStyle: "font-size: 32rpx;line-height: 32rpx;color: #999999;", placeholderStyle: 'font-size: 32rpx;line-height: 32rpx;color: #999999;',
loginList: [ loginList: [
// //
{ {
icon: "weixin-fill", icon: 'weixin-fill',
color: "#00a327", color: '#00a327',
title: "微信", title: '微信',
code: "WECHAT", code: 'WECHAT'
}, },
{ {
icon: "qq-fill", icon: 'qq-fill',
color: "#38ace9", color: '#38ace9',
title: "QQ", title: 'QQ',
code: "QQ", code: 'QQ'
}, },
{ {
icon: "apple-fill", icon: 'apple-fill',
color: "#000000", color: '#000000',
title: "Apple", title: 'Apple',
code: "APPLE", code: 'APPLE'
}, }
], ],
initurl: false, initurl: false
}; };
}, },
@ -198,7 +209,7 @@ export default {
//#ifdef H5 //#ifdef H5
let isWXBrowser = /micromessenger/i.test(navigator.userAgent); let isWXBrowser = /micromessenger/i.test(navigator.userAgent);
if (isWXBrowser) { if (isWXBrowser) {
webConnect("WECHAT").then((res) => { webConnect('WECHAT').then((res) => {
let data = res.data; let data = res.data;
if (data.success) { if (data.success) {
window.location = data.result; window.location = data.result;
@ -212,7 +223,7 @@ export default {
// #ifndef APP-PLUS // #ifndef APP-PLUS
// //
var ua = window.navigator.userAgent.toLowerCase(); var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") { if (ua.match(/MicroMessenger/i) == 'micromessenger') {
this.wechatLogin = true; this.wechatLogin = true;
return; return;
} }
@ -221,45 +232,45 @@ export default {
* 条件编译判断当前客户端类型 * 条件编译判断当前客户端类型
*/ */
//#ifdef H5 //#ifdef H5
this.clientType = "H5"; this.clientType = 'H5';
//#endif //#endif
//#ifdef APP-PLUS //#ifdef APP-PLUS
this.clientType = "APP"; this.clientType = 'APP';
/**如果是app 加载支持的登录方式*/ /**如果是app 加载支持的登录方式*/
let _this = this; let _this = this;
uni.getProvider({ uni.getProvider({
service: "oauth", service: 'oauth',
success: (result) => { success: (result) => {
_this.loginList = result.provider.map((value) => { _this.loginList = result.provider.map((value) => {
//title //title
let title = ""; let title = '';
//code //code
let code = ""; let code = '';
// //
let color = "#8b8b8b"; let color = '#8b8b8b';
// //
let icon = ""; let icon = '';
//uni code //uni code
let appcode = ""; let appcode = '';
switch (value) { switch (value) {
case "weixin": case 'weixin':
icon = "weixin-circle-fill"; icon = 'weixin-circle-fill';
color = "#00a327"; color = '#00a327';
title = "微信"; title = '微信';
code = "WECHAT"; code = 'WECHAT';
break; break;
case "qq": case 'qq':
icon = "qq-circle-fill"; icon = 'qq-circle-fill';
color = "#38ace9"; color = '#38ace9';
title = "QQ"; title = 'QQ';
code = "QQ"; code = 'QQ';
break; break;
case "apple": case 'apple':
icon = "apple-fill"; icon = 'apple-fill';
color = "#000000"; color = '#000000';
title = "Apple"; title = 'Apple';
code = "APPLE"; code = 'APPLE';
break; break;
} }
return { return {
@ -267,28 +278,28 @@ export default {
code: code, code: code,
color: color, color: color,
icon: icon, icon: icon,
appcode: value, appcode: value
}; };
}); });
}, },
fail: (error) => { fail: (error) => {
uni.showToast({ uni.showToast({
title: "获取登录通道失败" + error, title: '获取登录通道失败' + error,
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
}, }
}); });
//#endif //#endif
// //
// #ifdef H5 // #ifdef H5
this.methodFilter(["QQ"]); this.methodFilter(['QQ']);
// #endif // #endif
// //
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
this.methodFilter(["WECHAT"]); this.methodFilter(['WECHAT']);
// #endif // #endif
}, },
watch: { watch: {
@ -300,7 +311,7 @@ export default {
if (val.length == 11) { if (val.length == 11) {
this.enabuleFetchCode = true; this.enabuleFetchCode = true;
} }
}, }
}, },
async flage(val) { async flage(val) {
@ -318,20 +329,20 @@ export default {
uni.showToast({ uni.showToast({
title: res.data.message, title: res.data.message,
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
this.flage = false; this.flage = false;
} }
} else { } else {
this.$u.toast("请倒计时结束后再发送"); this.$u.toast('请倒计时结束后再发送');
} }
} else { } else {
this.$refs.verification.hide(); this.$refs.verification.hide();
} }
}, }
}, },
onLoad(options) { onLoad(options) {
if (options.init == "index") { if (options.init == 'index') {
this.initurl = true; this.initurl = true;
} }
if (options && options.state) { if (options && options.state) {
@ -342,7 +353,7 @@ export default {
customback() { customback() {
if (this.initurl) { if (this.initurl) {
uni.switchTab({ uni.switchTab({
url: "/pages/tabbar/vlog/index?init=ok", url: '/pages/tabbar/vlog/index?init=ok'
}); });
} else { } else {
uni.navigateBack(); uni.navigateBack();
@ -358,8 +369,8 @@ export default {
storage.setRefreshToken(data.result.refreshToken); storage.setRefreshToken(data.result.refreshToken);
// //
uni.showToast({ uni.showToast({
title: "登录成功!", title: '登录成功!',
icon: "none", icon: 'none'
}); });
getUserInfo().then((user) => { getUserInfo().then((user) => {
storage.setUserInfo(user.data.result); storage.setUserInfo(user.data.result);
@ -367,10 +378,10 @@ export default {
}); });
getCurrentPages().length > 1 getCurrentPages().length > 1
? uni.navigateBack({ ? uni.navigateBack({
delta: getCurrentPages().length - 2, delta: getCurrentPages().length - 2
}) })
: uni.switchTab({ : uni.switchTab({
url: "/pages/tabbar/home/index", url: '/pages/tabbar/home/index'
}); });
} }
}); });
@ -387,9 +398,9 @@ export default {
}); });
} else { } else {
uni.showToast({ uni.showToast({
title: "配置有误请联系管理员", title: '配置有误请联系管理员',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
} }
}); });
@ -402,20 +413,20 @@ export default {
await uni.login({ await uni.login({
provider: item.appcode, provider: item.appcode,
// #ifdef MP-ALIPAY // #ifdef MP-ALIPAY
scopes: "auth_user", // scopes: 'auth_user', //
// #endif // #endif
success: function (res) { success: function (res) {
uni.setStorageSync("type", item.code); uni.setStorageSync('type', item.code);
//storageopenid //storageopenid
// #ifndef MP-WEIXIN // #ifndef MP-WEIXIN
uni.setStorageSync("openid", res.authResult.openid); uni.setStorageSync('openid', res.authResult.openid);
// #endif // #endif
}, },
fail(e) { fail(e) {
uni.showToast({ uni.showToast({
title: "第三方登录暂不可用!", title: '第三方登录暂不可用!',
icon: "none", icon: 'none',
duration: 3000, duration: 3000
}); });
}, },
complete(e) { complete(e) {
@ -424,43 +435,43 @@ export default {
provider: item.appcode, provider: item.appcode,
success: function (infoRes) { success: function (infoRes) {
// //
uni.setStorageSync("nickname", infoRes.userInfo.nickName); uni.setStorageSync('nickname', infoRes.userInfo.nickName);
uni.setStorageSync("avatar", infoRes.userInfo.avatarUrl); uni.setStorageSync('avatar', infoRes.userInfo.avatarUrl);
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
//openid openiduni-id: https://uniapp.dcloud.net.cn/uniCloud/uni-id //openid openiduni-id: https://uniapp.dcloud.net.cn/uniCloud/uni-id
_this.weixinMPOpenID(res).then((res) => { _this.weixinMPOpenID(res).then((res) => {
//openid使openid //openid使openid
_this.goOpenidLogin("WECHAT_MP"); _this.goOpenidLogin('WECHAT_MP');
}); });
// #endif // #endif
// #ifndef MP-WEIXIN // #ifndef MP-WEIXIN
_this.goOpenidLogin("APP"); _this.goOpenidLogin('APP');
//#endif //#endif
}, }
}); });
}, }
}); });
}, },
//openid //openid
goOpenidLogin(clientType) { goOpenidLogin(clientType) {
// //
let params = { let params = {
uuid: uni.getStorageSync("openid"), //id uuid: uni.getStorageSync('openid'), //id
source: uni.getStorageSync("type"), // source: uni.getStorageSync('type'), //
nickname: uni.getStorageSync("nickname"), // nickname: uni.getStorageSync('nickname'), //
avatar: uni.getStorageSync("avatar"), // avatar: uni.getStorageSync('avatar'), //
uniAccessToken: uni.getStorageSync("uni_access_token"), //token uniAccessToken: uni.getStorageSync('uni_access_token') //token
}; };
openIdLogin(params, clientType).then((res) => { openIdLogin(params, clientType).then((res) => {
if (!res.data.success) { if (!res.data.success) {
let errormessage = "第三方登录暂不可用"; let errormessage = '第三方登录暂不可用';
uni.showToast({ uni.showToast({
// title: '', // title: '',
title: errormessage, title: errormessage,
icon: "none", icon: 'none',
duration: 3000, duration: 3000
}); });
return; return;
} else { } else {
@ -473,8 +484,8 @@ export default {
storage.setVlogUserInfo(vlogInfo); storage.setVlogUserInfo(vlogInfo);
// //
uni.showToast({ uni.showToast({
title: "第三方登录成功!", title: '第三方登录成功!',
icon: "none", icon: 'none'
}); });
// //
getUserInfo().then((user) => { getUserInfo().then((user) => {
@ -493,7 +504,7 @@ export default {
whetherNavigate(); whetherNavigate();
} else { } else {
uni.switchTab({ uni.switchTab({
url: "/pages/tabbar/home/index", url: '/pages/tabbar/home/index'
}); });
} }
}); });
@ -503,7 +514,7 @@ export default {
//openid //openid
async weixinMPOpenID(res) { async weixinMPOpenID(res) {
await miniProgramLogin(res.code).then((res) => { await miniProgramLogin(res.code).then((res) => {
uni.setStorageSync("openid", res.data); uni.setStorageSync('openid', res.data);
}); });
}, },
/**跳转到登录页面 */ /**跳转到登录页面 */
@ -511,10 +522,7 @@ export default {
// #ifdef H5 // #ifdef H5
let code = connectLogin.code; let code = connectLogin.code;
let buyer = api.buyer; let buyer = api.buyer;
window.open( window.open(buyer + `/passport/connect/connect/login/web/` + code, '_self');
buyer + `/passport/connect/connect/login/web/` + code,
"_self"
);
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
this.nonH5OpenId(connectLogin); this.nonH5OpenId(connectLogin);
@ -527,23 +535,26 @@ export default {
* 清空当前账号信息 * 清空当前账号信息
*/ */
storage.setHasLogin(false); storage.setHasLogin(false);
storage.setAccessToken(""); storage.setAccessToken('');
storage.setRefreshToken(""); storage.setRefreshToken('');
storage.setUuid('');
storage.setUserInfo({}); storage.setUserInfo({});
// vlog // vlog
storage.setVlogToken(""); storage.setVlogToken('');
storage.setVlogUserInfo({}); storage.setVlogUserInfo(null);
//
storage.setRefreshVlogIndex('1'); //
/** /**
* 执行登录 * 执行登录
*/ */
smsLogin( smsLogin(
{ {
mobile: this.mobile, mobile: this.mobile,
code: this.code, code: this.code
}, },
this.clientType this.clientType
).then((res) => { ).then((res) => {
// console.log(res) console.log(res);
if (res.data.success) { if (res.data.success) {
const infoData = res.data.result; const infoData = res.data.result;
const vlogInfo = JSON.parse(infoData.tikUser); const vlogInfo = JSON.parse(infoData.tikUser);
@ -564,10 +575,12 @@ export default {
*/ */
storage.setUserInfo(user.data.result); storage.setUserInfo(user.data.result);
storage.setHasLogin(true); storage.setHasLogin(true);
// loginIm
loginIm();
// //
uni.showToast({ uni.showToast({
title: "登录成功!", title: '登录成功!',
icon: "none", icon: 'none'
}); });
/** /**
@ -578,7 +591,7 @@ export default {
whetherNavigate(); whetherNavigate();
} else { } else {
uni.switchTab({ uni.switchTab({
url: "/pages/tabbar/home/index", url: '/pages/tabbar/home/index'
}); });
} }
}); });
@ -594,13 +607,13 @@ export default {
// //
navigateToPrivacy(val) { navigateToPrivacy(val) {
uni.navigateTo({ uni.navigateTo({
url: "/pages/mine/help/tips?type=" + val, url: '/pages/mine/help/tips?type=' + val
}); });
}, },
// //
start() { start() {
this.codeColor = "#999"; this.codeColor = '#999';
this.$u.toast("验证码已发送"); this.$u.toast('验证码已发送');
this.flage = false; this.flage = false;
this.codeFlag = false; this.codeFlag = false;
@ -620,24 +633,24 @@ export default {
fetchCode() { fetchCode() {
if (!this.enabulePrivacy) { if (!this.enabulePrivacy) {
uni.showToast({ uni.showToast({
title: "请同意用户隐私", title: '请同意用户隐私',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
return false; return false;
} }
if (!this.$u.test.mobile(this.mobile)) { if (!this.$u.test.mobile(this.mobile)) {
uni.showToast({ uni.showToast({
title: "请填写正确手机号", title: '请填写正确手机号',
duration: 2000, duration: 2000,
icon: "none", icon: 'none'
}); });
return false; return false;
} }
if (this.tips == "重新获取验证码") { if (this.tips == '重新获取验证码') {
uni.showLoading({ uni.showLoading({
title: "加载中", title: '加载中'
}); });
if (!this.codeFlag) { if (!this.codeFlag) {
let timer = setInterval(() => { let timer = setInterval(() => {
@ -654,8 +667,8 @@ export default {
return false; return false;
} }
}, }
}, }
}; };
</script> </script>
<style> <style>
@ -708,11 +721,11 @@ page {
.disable { .disable {
// background: linear-gradient(90deg, #ffdcba 2.21%, #ffcfb2 99.86%); // background: linear-gradient(90deg, #ffdcba 2.21%, #ffcfb2 99.86%);
background: #FE3C3C; background: #fe3c3c;
} }
.fetch { .fetch {
background: #FE3C3C; background: #fe3c3c;
} }
.btn { .btn {
@ -775,7 +788,7 @@ page {
.imgage { .imgage {
width: 100%; width: 100%;
height: 37.5vh; height: 37.5vh;
background: url("./static/logn.png"); background: url('./static/logn.png');
background-size: 100% 100%; background-size: 100% 100%;
& > div { & > div {
width: 100%; width: 100%;

View File

@ -95,6 +95,7 @@ import api from '@/config/api.js';
export default { export default {
data() { data() {
return { return {
upFlage: true,
publishTouched: false, publishTouched: false,
preplayTouched: false, preplayTouched: false,
tempFilePath: '', tempFilePath: '',
@ -107,6 +108,7 @@ export default {
}; };
}, },
onLoad(params) { onLoad(params) {
this.upFlage = false;
let me = this; let me = this;
let vlogInfo = storage.getVlogUserInfo(); let vlogInfo = storage.getVlogUserInfo();
// 上个页面传过来的文件事件对象, 其中包含了相册中选择的视频内容 // 上个页面传过来的文件事件对象, 其中包含了相册中选择的视频内容
@ -147,6 +149,9 @@ export default {
// (res.progress * 100) / res.total // (res.progress * 100) / res.total
// ); // );
me.percentCompleted = res.progress; me.percentCompleted = res.progress;
if (res.progress == 100) {
me.upFlage = true;
}
}); });
}, },
methods: { methods: {
@ -155,6 +160,9 @@ export default {
this.title = e.detail.value; this.title = e.detail.value;
}, },
doPublich() { doPublich() {
if (!this.upFlage) {
return;
}
if (this.title.length < 5) { if (this.title.length < 5) {
uni.showToast({ uni.showToast({
title: '请输入5个字以上的标题', title: '请输入5个字以上的标题',
@ -162,6 +170,10 @@ export default {
}); });
return; return;
} }
this.upFlage = false;
uni.showLoading({
title: '请稍等'
});
let me = this; let me = this;
let vlogInfo = storage.getVlogUserInfo(); let vlogInfo = storage.getVlogUserInfo();
let userId = vlogInfo.id; let userId = vlogInfo.id;
@ -187,17 +199,15 @@ export default {
data: vlog, data: vlog,
success(result) { success(result) {
if (result.data.status == 200) { if (result.data.status == 200) {
uni.showToast({ // uni.showToast({
title: result.data.msg, // title: result.data.msg,
icon: 'none', // icon: 'none',
duration: 2000 // duration: 2000
}); // });
setTimeout(() => {
uni.switchTab({ uni.switchTab({
url: '/pages/me/me' url: '/pages/me/me'
}); });
}, 2000);
} else { } else {
uni.showToast({ uni.showToast({
title: result.data.msg, title: result.data.msg,
@ -205,6 +215,10 @@ export default {
duration: 3000 duration: 3000
}); });
} }
},
complete() {
this.upFlage = true;
uni.hideLoading();
} }
}); });
}, },

View File

@ -114,6 +114,10 @@ export default {
} }
data.forEach((i) => { data.forEach((i) => {
i.doIflow = false; i.doIflow = false;
if (i.followStatus == null) {
//
i.followStatus = '未关注';
}
this.flowList.push(i); this.flowList.push(i);
}); });
// this.flowList.push(...data); // this.flowList.push(...data);

View File

@ -1,5 +1,8 @@
<template> <template>
<div style="height: 100%" @click="handleTouchStart"> <div
style="height: 100%"
@click="handleTouchStart"
>
<div class="jolkp"> <div class="jolkp">
<div <div
class="fan" class="fan"
@ -29,9 +32,16 @@
v-if="statue == 0 || 6" v-if="statue == 0 || 6"
:style="{ marginTop: '45px' }" :style="{ marginTop: '45px' }"
></div> ></div>
<view class="jolkp_l" :style="{ marginTop: '45px' }"></view> <view
class="jolkp_l"
:style="{ marginTop: '45px' }"
></view>
<!-- 弹出框 --> <!-- 弹出框 -->
<view v-if="isPopupVisible" class="popup" ref="popup"> <view
v-if="isPopupVisible"
class="popup"
ref="popup"
>
<ul> <ul>
<li @click="handleAddFriend">添加好友/群聊</li> <li @click="handleAddFriend">添加好友/群聊</li>
<li @click="handleMenu()">发起群聊</li> <li @click="handleMenu()">发起群聊</li>
@ -40,9 +50,15 @@
</view> </view>
</div> </div>
<!-- 搜索添加 --> <!-- 搜索添加 -->
<TUIContactsea v-if="statue == 2" @switchConversation="hui" /> <TUIContactsea
v-if="statue == 2"
@switchConversation="hui"
/>
<!-- 联系人 --> <!-- 联系人 -->
<TUIContact v-else-if="statue == 1" style="height: 100%" /> <TUIContact
v-else-if="statue == 1"
style="height: 100%"
/>
<!-- 群选择的 --> <!-- 群选择的 -->
<SelectFriend <SelectFriend
v-else-if="statue == 3" v-else-if="statue == 3"
@ -50,9 +66,18 @@
:style="{ marginTop: '20px', heigth: '80%' }" :style="{ marginTop: '20px', heigth: '80%' }"
/> />
<!-- 群类型 --> <!-- 群类型 -->
<CreateGroup v-else-if="statue == 10" @con="confn" /> <CreateGroup
<SelectFriendqlioa v-else-if="statue == 4" @concen="concen" /> v-else-if="statue == 10"
<ContactInfo v-else-if="statue == 7" @concen="concen" /> @con="confn"
/>
<SelectFriendqlioa
v-else-if="statue == 4"
@concen="concen"
/>
<ContactInfo
v-else-if="statue == 7"
@concen="concen"
/>
<!-- 站内信数据 --> <!-- 站内信数据 -->
<!-- <div > --> <!-- <div > -->
<scroll-view <scroll-view
@ -85,48 +110,45 @@
<!-- </div> --> <!-- </div> -->
<!-- 会话 --> <!-- 会话 -->
<TUIConversation style="height: 100%" v-else @state="state" /> <TUIConversation
style="height: 100%"
v-else
@state="state"
/>
<!-- 未登录显示 -->
<view
v-if="showNoLoginPage"
class="no-login"
@click="toLogin"
>
请登录
</view>
</div> </div>
</template> </template>
<script> <script>
// //
import TUIConversation from "@/TUIKit/components/TUIConversation/index"; import TUIConversation from '@/TUIKit/components/TUIConversation/index';
import TUIContact from "@/TUIKit/components/TUIContact/index"; import TUIContact from '@/TUIKit/components/TUIContact/index';
import TUIContactsea from "@/TUIKit/components/TUIContact/indexsea"; import TUIContactsea from '@/TUIKit/components/TUIContact/indexsea';
import { TUILogin } from "@tencentcloud/tui-core"; import { TUILogin } from '@tencentcloud/tui-core';
import ContactSearch from "@/TUIKit/components/TUIContact/contact-search/index.vue"; import ContactSearch from '@/TUIKit/components/TUIContact/contact-search/index.vue';
import CreateGroup from "@/TUIKit/components/TUIGroup/create-group/index.vue"; import CreateGroup from '@/TUIKit/components/TUIGroup/create-group/index.vue';
import { TUIChatKit } from "@/TUIKit"; // import { TUIChatKit } from '@/TUIKit';
import SelectFriend from "@/TUIKit/components/TUIContact/select-friend/index.vue"; import SelectFriend from '@/TUIKit/components/TUIContact/select-friend/index.vue';
import ContactInfo from "@/TUIKit/components/TUIContact/contact-info/index.vue"; import ContactInfo from '@/TUIKit/components/TUIContact/contact-info/index.vue';
import SelectFriendqlioa from "@/TUIKit/components/TUIGroup/index.vue"; import SelectFriendqlioa from '@/TUIKit/components/TUIGroup/index.vue';
import TUICore, { ExtensionInfo, TUIConstants } from "@tencentcloud/tui-core"; import TUICore, { ExtensionInfo, TUIConstants } from '@tencentcloud/tui-core';
import storage from "@/utils/storage.js"; import storage from '@/utils/storage.js';
// push // push
import { TUIConversationService } from "@tencentcloud/chat-uikit-engine"; // import { TUIConversationService } from '@tencentcloud/chat-uikit-engine';
import * as Push from "@/uni_modules/TencentCloud-Push"; // import * as Push from '@/uni_modules/TencentCloud-Push';
import { import { getUserimInfo, getMember, getMemberstate, getMemberdelete, geterweijki } from '@/api/members';
getUserimInfo, import { TUITranslateService, TUIStore, StoreName, IGroupModel, TUIFriendService, Friend, FriendApplication, TUIUserService } from '@tencentcloud/chat-uikit-engine';
getMember, // TUIChatKit.init();
getMemberstate, // let vueVersion = 2;
getMemberdelete,
geterweijki,
} from "@/api/members";
import {
TUITranslateService,
TUIStore,
StoreName,
IGroupModel,
TUIFriendService,
Friend,
FriendApplication,
TUIUserService,
} from "@tencentcloud/chat-uikit-engine";
TUIChatKit.init();
let vueVersion = 2;
// vueVersion = 3; // vueVersion = 3;
export default { export default {
@ -138,12 +160,13 @@ export default {
ContactSearch, ContactSearch,
SelectFriend, SelectFriend,
SelectFriendqlioa, SelectFriendqlioa,
TUIChatKit, // TUIChatKit,
CreateGroup, CreateGroup,
ContactInfo, ContactInfo
}, },
data() { data() {
return { return {
showNoLoginPage: false,
statue: 0, // 0 1 2/ 3 4 6 10 7 statue: 0, // 0 1 2/ 3 4 6 10 7
isPopupVisible: false, // isPopupVisible: false, //
isq: false, isq: false,
@ -152,90 +175,48 @@ export default {
swipeStates: [], swipeStates: [],
startX: 0, startX: 0,
tole: 0, // tole: 0, //
cleartime: null, timer: null, //
pageSize: 20, pageSize: 20,
pageNumber: 1, pageNumber: 1,
total: 0, total: 0,
loadMoreStatus: "more", // loadMoreStatus: 'more' //
}; };
}, },
created() {}, onTabItemTap(e) {
onShow() { let tabIndex = e.index;
// console.log(tabIndex);
// if (tabIndex == 2) {
getUserimInfo() //
.then(({ data }) => { if (!storage.getHasLogin()) {
if (data.code == 200) { this.removeTimer();
const par = data.result; //
TUILogin.login({ uni.navigateTo({
SDKAppID: par.sdkAppId, url: '/pages/passport/login'
userID: par.userID,
userSig: par.userSig,
useUploadPlugin: true, // If you need to send rich media messages, please set to true.
framework: `vue${vueVersion}`, // framework used vue2 / vue3
}).then(() => {
Push.setRegistrationID(par.userID, () => {
console.log(
"设置id设置id设置id设置id设置id设置id设置id设置id设置id设置id",
par.userID
);
Push.registerPush(
par.sdkAppId,
"vkFpe55aYqfV7Sk5uGaoxhEstJ3tcI9dquk7JwG1GloDSLD2HeMWeQweWWXgNlhC",
(data) => {
console.log("registerPush ok", data);
Push.getRegistrationID((registrationID) => {
console.log("getRegistrationID ok", registrationID);
});
},
(errCode, errMsg) => {
console.error("registerPush failed", errCode, errMsg);
}
);
});
//
Push.addPushListener(Push.EVENT.NOTIFICATION_CLICKED, (res) => {
console.log("notification clicked", res);
//
try {
const data = JSON.parse(res.data);
const conv_type =
data?.entity?.chatType === 1 ? "C2C" : "GROUP";
// conversationID
const conversationID = `${conv_type}${data.entity.sender}`;
//
TUIConversationService.switchConversation(conversationID);
const chatPath = "/TUIKit/components/TUIChat/index";
uni.navigateTo({ url: chatPath });
} catch (error) {
console.log("error", error);
}
});
// 线
Push.addPushListener(Push.EVENT.MESSAGE_RECEIVED, (res) => {
// res
console.log("message received", res);
});
// 线
Push.addPushListener(Push.EVENT.MESSAGE_REVOKED, (res) => {
// res ID
console.log("message revoked", res);
});
}); });
this.showNoLoginPage = true;
} else { } else {
// 200 this.removeTimer();
uni.navigateTo({ this.setTime();
url: "/pages/passport/login", this.showNoLoginPage = false;
}); }
}
},
onUnload() {},
created() {},
onHide() {
console.log('IM页面隐藏');
this.removeTimer();
},
onShow() {
//
if (!storage.getHasLogin()) {
this.removeTimer();
//
this.showNoLoginPage = true;
} else {
this.setTime();
this.showNoLoginPage = false;
} }
})
.catch(() => {
//
uni.navigateTo({
url: "/pages/passport/login",
});
});
}, },
mounted() { mounted() {
@ -243,7 +224,7 @@ export default {
this.setTime(); this.setTime();
// //
uni.$on("globalClick", (event) => { uni.$on('globalClick', (event) => {
// console.log(event, "====+++"); // console.log(event, "====+++");
this.handleGlobalClick(event); this.handleGlobalClick(event);
}); });
@ -255,35 +236,39 @@ export default {
}, },
beforeDestroy() { beforeDestroy() {
// //
uni.$off("globalClick"); uni.$off('globalClick');
// //
clearTimeout(this.cleartime); this.removeTimer();
}, },
methods: { methods: {
toLogin() {
uni.navigateTo({
url: '/pages/passport/login'
});
},
state(item) { state(item) {
this.isPopupVisible = item; this.isPopupVisible = item;
}, },
handleTouchStart(event) { handleTouchStart(event) {
uni.$emit("globalClick", event); uni.$emit('globalClick', event);
}, },
handleGlobalClick(event) { handleGlobalClick(event) {
const query = uni.createSelectorQuery().in(this); const query = uni.createSelectorQuery().in(this);
query query
.select(".jolkp_l") .select('.jolkp_l')
// //
.boundingClientRect((rect) => { .boundingClientRect((rect) => {
if (rect) { if (rect) {
const clickX = event.clientX || event.touches[0].clientX; const clickX = event.clientX || event.touches[0].clientX;
const clickY = event.clientY || event.touches[0].clientY; const clickY = event.clientY || event.touches[0].clientY;
if (clickX >= rect.left && clickX <= rect.width+rect.left if (clickX >= rect.left && clickX <= rect.width + rect.left && clickY >= rect.top && clickY <= rect.top + rect.height * 2) {
&& clickY >= rect.top && clickY <= rect.top + rect.height*2) {
// this.statue = 0; // // this.statue = 0; //
console.log("点击是在节点范围"); console.log('点击是在节点范围');
this.isPopupVisible = !this.isPopupVisible; // this.isPopupVisible = !this.isPopupVisible; //
} else { } else {
// this.statue = 0; // // this.statue = 0; //
console.log("否"); console.log('否');
this.isPopupVisible = false; // this.isPopupVisible = false; //
} }
} }
@ -299,11 +284,18 @@ export default {
this.getMembermethod(); this.getMembermethod();
} }
}, },
removeTimer() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
},
setTime() { setTime() {
const th = this; if (this.timer) {
this.cleartime = setTimeout(() => { return;
}
this.timer = setInterval(() => {
this.getMembermethod(); this.getMembermethod();
th.setTime(); //setTime10getMembermethod
}, 10000); }, 10000);
}, },
torut(item) { torut(item) {
@ -311,7 +303,7 @@ export default {
const itemJson = encodeURIComponent(JSON.stringify(item)); const itemJson = encodeURIComponent(JSON.stringify(item));
// 使 uni.navigateTo // 使 uni.navigateTo
uni.navigateTo({ uni.navigateTo({
url: `/pages/tabbar/im/details/index?item=${itemJson}`, url: `/pages/tabbar/im/details/index?item=${itemJson}`
}); });
getMemberstate({ messageId: item.messageId }).then((res) => { getMemberstate({ messageId: item.messageId }).then((res) => {
this.getMembermethod(); this.getMembermethod();
@ -336,7 +328,7 @@ export default {
getMembermethod() { getMembermethod() {
const param = { const param = {
pageSize: this.pageSize, pageSize: this.pageSize,
pageNumber: this.pageNumber, pageNumber: this.pageNumber
}; };
getMember(param).then((res) => { getMember(param).then((res) => {
this.total = res.data.result.total; this.total = res.data.result.total;
@ -346,22 +338,16 @@ export default {
this.meList = this.meList.concat(res.data.result.records); this.meList = this.meList.concat(res.data.result.records);
} }
this.swipeStates = new Array(this.meList.length).fill(0); this.swipeStates = new Array(this.meList.length).fill(0);
this.tole = this.meList.filter( this.tole = this.meList.filter((item) => item.status === 'UN_READY').length;
(item) => item.status === "UN_READY"
).length;
}); });
}, },
handleMenu() { handleMenu() {
const fn = [ const fn = [...TUICore.getExtensionList(TUIConstants.TUISearch.EXTENSION.SEARCH_MORE.EXT_ID)];
...TUICore.getExtensionList(
TUIConstants.TUISearch.EXTENSION.SEARCH_MORE.EXT_ID
),
];
const item = fn[1]; const item = fn[1];
const { const {
listener = { listener = {
onClicked: () => {}, onClicked: () => {}
}, }
} = item; } = item;
listener?.onClicked?.(item); listener?.onClicked?.(item);
this.statue = 3; this.statue = 3;
@ -375,39 +361,54 @@ export default {
this.isPopupVisible = false; this.isPopupVisible = false;
uni.scanCode({ uni.scanCode({
success: (res) => { success: (res) => {
console.log("扫码结果:---", res.result); console.log('扫码结果:---', res.result);
const params = { const params = {
userID: res.result, //userID userID: res.result //userID
}; };
console.log("params", params); console.log('params', params);
TUIStore.update(StoreName.CUSTOM, "currentContactInfo", params); TUIStore.update(StoreName.CUSTOM, 'currentContactInfo', params);
this.statue = 7; this.statue = 7;
}, }
}); });
}, },
startLongPress(item, index) { startLongPress(item, index) {
this.longPressTimer = setTimeout(() => { this.longPressTimer = setTimeout(() => {
uni.showModal({ uni.showModal({
title: "确认删除", title: '确认删除',
content: "确定要删除这条消息吗?", content: '确定要删除这条消息吗?',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
getMemberdelete({ messageId: item.messageId }).then((res) => { getMemberdelete({ messageId: item.messageId }).then((res) => {
this.getMembermethod(); this.getMembermethod();
}); });
} }
}, }
}); });
}, 2000); }, 2000);
}, },
endLongPress() { endLongPress() {
clearTimeout(this.longPressTimer); clearTimeout(this.longPressTimer);
}, }
}, }
}; };
</script> </script>
<style scoped> <style scoped>
.no-login {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: #000;
display: flex;
align-items: center;
justify-content: center;
z-index: 9999999;
font-size: 36rpx;
font-weight: 600;
color: #fff;
}
uni-page-body, uni-page-body,
html, html,
body, body,
@ -417,6 +418,8 @@ page {
overflow: hidden; overflow: hidden;
} }
.jolkp { .jolkp {
position: sticky;
top: 0;
height: 75px; height: 75px;
display: flex; display: flex;
font-size: 15px; font-size: 15px;
@ -433,7 +436,7 @@ page {
.jolkp_l { .jolkp_l {
width: 1.8rem; width: 1.8rem;
height: 1.8rem; height: 1.8rem;
background-image: url("@/static/im/Frame.png"); background-image: url('@/static/im/Frame.png');
/* 让背景图覆盖整个元素 */ /* 让背景图覆盖整个元素 */
background-size: cover; background-size: cover;
/* 背景图不重复 */ /* 背景图不重复 */
@ -445,7 +448,7 @@ page {
.jolkp_h { .jolkp_h {
width: 1.8rem; width: 1.8rem;
height: 1.8rem; height: 1.8rem;
background-image: url("@/static/im/user.png"); background-image: url('@/static/im/user.png');
/* 让背景图覆盖整个元素 */ /* 让背景图覆盖整个元素 */
background-size: cover; background-size: cover;
/* 背景图不重复 */ /* 背景图不重复 */
@ -456,7 +459,7 @@ page {
.jolkp_z { .jolkp_z {
width: 1.8rem; width: 1.8rem;
height: 1.8rem; height: 1.8rem;
background-image: url("@/static/im/znx.png"); background-image: url('@/static/im/znx.png');
/* 让背景图覆盖整个元素 */ /* 让背景图覆盖整个元素 */
background-size: cover; background-size: cover;
/* 背景图不重复 */ /* 背景图不重复 */
@ -499,7 +502,7 @@ page {
.fan { .fan {
width: 10%; width: 10%;
height: "100%"; height: '100%';
font-size: 18px; font-size: 18px;
display: flex; display: flex;
@ -509,7 +512,7 @@ page {
.fan { .fan {
margin-right: 56% !important; margin-right: 56% !important;
width: 10%; width: 10%;
height: "100%"; height: '100%';
font-size: 18px; font-size: 18px;
display: flex; display: flex;
margin-top: 80%; margin-top: 80%;
@ -535,7 +538,7 @@ page {
.three_div1 { .three_div1 {
height: 3rem; height: 3rem;
width: 40%; width: 40%;
background-image: url("@/static/im/kf.png"); background-image: url('@/static/im/kf.png');
background-size: 100% 100%; background-size: 100% 100%;
background-repeat: no-repeat; background-repeat: no-repeat;
display: flex; display: flex;
@ -546,7 +549,7 @@ page {
.three_div2 { .three_div2 {
width: 40%; width: 40%;
height: 3rem; height: 3rem;
background-image: url("@/static/im/hy.png"); background-image: url('@/static/im/hy.png');
background-size: 100% 100%; background-size: 100% 100%;
background-repeat: no-repeat; background-repeat: no-repeat;
width: 40%; width: 40%;
@ -554,7 +557,7 @@ page {
.three_div3 { .three_div3 {
height: 3rem; height: 3rem;
background-image: url("@/static/im/da.png"); background-image: url('@/static/im/da.png');
background-size: 100% 100%; background-size: 100% 100%;
background-repeat: no-repeat; background-repeat: no-repeat;
width: 40%; width: 40%;

View File

@ -210,13 +210,32 @@ export default {
let tabIndex = e.index; let tabIndex = e.index;
if (tabIndex == 0) { if (tabIndex == 0) {
var prop = this.pageList[this.curIndex]; var prop = this.pageList[this.curIndex];
// this.$refs[prop].showVd();
console.log('是否刷新:' + storage.getRefreshVlogIndex());
if (storage.getRefreshVlogIndex() === '1') {
try {
storage.setRefreshVlogIndex('0'); //初始完数据修改状态不需要刷新
console.log('是否刷新:' + storage.getRefreshVlogIndex());
// 登录后需要刷新数据
for (var i = 0; i < this.pageList.length; i++) {
this.$refs[i].dataList = []; //所有数据清空
}
this.$refs[prop].get(); //只初始化当前所在位置的数据
} catch (err) {
console.log(err + '255');
}
} else {
try {
this.$refs[prop].showVd(); this.$refs[prop].showVd();
} catch (err) {
console.log(err);
}
}
} }
}, },
onShow() { onShow() {
var prop = this.pageList[this.curIndex]; var prop = this.pageList[this.curIndex];
this.getLocation(); this.getLocation();
this.myUserInfo = storage.getVlogUserInfo();
if (storage.getRefreshVlogIndex() == '1') { if (storage.getRefreshVlogIndex() == '1') {
// 登录后需要刷新数据 // 登录后需要刷新数据
for (var i = 0; i < this.pageList.length; i++) { for (var i = 0; i < this.pageList.length; i++) {

View File

@ -15,13 +15,16 @@
.all-box { .all-box {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-around; /* justify-content: space-around; */
height: 280rpx; height: 280rpx;
} }
.share-item { .share-item {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-top: 60rpx; margin-top: 60rpx;
margin-left: 20rpx;
margin-right: 20rpx;
width: 120rpx;
} }
.icon-wrapper { .icon-wrapper {
width: 120rpx; width: 120rpx;
@ -39,8 +42,12 @@
} }
.icon-tag-text { .icon-tag-text {
color: #ffffff; color: #ffffff;
width: 120rpx;
font-size: 14px; font-size: 14px;
margin-top: 10rpx; margin-top: 10rpx;
lines: 1;
text-overflow: ellipsis;
text-align: center;
} }
</style> </style>
@ -70,6 +77,7 @@
</view> --> </view> -->
<view <view
v-if="userId == ''"
class="share-item" class="share-item"
@click="copyLink()" @click="copyLink()"
> >
@ -90,6 +98,73 @@
复制链接 复制链接
</text> </text>
</view> </view>
<!-- 会话列表 storage.getHasLogin() -->
<scroll-view
v-if="userId != ''"
:scroll-x="true"
:show-scrollbar="false"
class="all-box"
>
<view
class="share-item"
@click="copyLink()"
>
<view
class="icon-wrapper"
style="align-self: center"
>
<image
class="icon-image"
src="/static/images/link.png"
style="align-self: center"
></image>
</view>
<text
class="icon-tag-text"
style="align-self: center"
>
复制链接
</text>
</view>
<view
v-for="(i, index) in converList"
:key="index"
class="share-item"
@click="toIm(i)"
>
<view
class="icon-wrapper"
style="align-self: center"
>
<image
v-if="i.type == 'C2C'"
class="icon-image"
:src="i.userProfile.avatar || ''"
style="align-self: center"
></image>
<image
v-if="i.type == 'GROUP'"
class="icon-image"
:src="i.groupProfile.avatar || ''"
style="align-self: center"
></image>
</view>
<text
v-if="i.type == 'C2C'"
class="icon-tag-text"
style="align-self: center"
>
{{ i.userProfile.nick || '' }}
</text>
<text
v-if="i.type == 'GROUP'"
class="icon-tag-text"
style="align-self: center"
>
{{ i.groupProfile.name || '' }}
</text>
</view>
</scroll-view>
<!-- <view <!-- <view
class="share-item" class="share-item"
@ -190,8 +265,10 @@
<script> <script>
import storage from '@/utils/storage.js'; // import storage from '@/utils/storage.js'; //
import config from '@/config/config.js';
import { vlogChangeToPublic, vlogChangeToPrivate } from '@/api/vlog'; import { vlogChangeToPublic, vlogChangeToPrivate } from '@/api/vlog';
import { dateFormat, graceNumber, getDateBeforeNow } from '@/utils/tools.js'; import { dateFormat, graceNumber, getDateBeforeNow } from '@/utils/tools.js';
import { conversationData, sendVlogCustomMsg } from '@/utils/handleim.js';
import popup from '../uni-popup/popup.js'; import popup from '../uni-popup/popup.js';
export default { export default {
name: 'UniPopupShare', name: 'UniPopupShare',
@ -221,12 +298,15 @@ export default {
isPrivate: { isPrivate: {
type: Number, type: Number,
default: 0 default: 0
} },
vlogItem: {}
}, },
data() { data() {
return { return {
userId: '', userId: '',
cancelTouched: false cancelTouched: false,
converList: [],
flag: true
}; };
}, },
@ -234,10 +314,51 @@ export default {
console.log('挂载'); console.log('挂载');
var info = storage.getVlogUserInfo(); var info = storage.getVlogUserInfo();
if (info != null) { if (info != null) {
console.log('登录了');
this.userId = info.id; this.userId = info.id;
this.conversationList();
} }
}, },
methods: { methods: {
//
async conversationList() {
var data = await conversationData();
console.log(data);
this.converList = data.data.conversationList;
console.log(this.converList);
},
toIm(i) {
if (this.flag) {
this.flag = false;
sendVlogCustomMsg(i, this.vlogItem)
.then((res) => {
console.log('发送成功,返回结果:', res);
uni.showToast({
icon: 'success',
title: '分享成功',
duration: 3000
});
var timer = setTimeout(() => {
clearTimeout(timer);
this.flag = true;
}, 3000);
})
.catch((err) => {
this.flag = true;
console.error('发送失败了', err);
//
uni.showToast({
icon: 'error',
title: '云服务异常'
});
});
} else {
uni.showToast({
icon: 'none',
title: '点太快了'
});
}
},
/** /**
* 选择内容 * 选择内容
*/ */
@ -293,8 +414,9 @@ export default {
copyLink() { copyLink() {
// this.thisVlogId id // this.thisVlogId id
var url = config.shareLink + '/pages/me/vlog?vlogId=' + this.thisVlogId;
uni.setClipboardData({ uni.setClipboardData({
data: this.vlogUrl, data: url,
success: () => { success: () => {
uni.showToast({ uni.showToast({
// //

216
utils/handleim.js Normal file
View File

@ -0,0 +1,216 @@
import {
getUserimInfo
} from '@/api/members';
import {
TUILogin
} from '@tencentcloud/tui-core';
import {
TUIConversationService,
} from '@tencentcloud/chat-uikit-engine';
import {
TUIGlobal
} from '@tencentcloud/universal-api';
import * as Push from '@/uni_modules/TencentCloud-Push';
import storage from "@/utils/storage.js";
// sdkStateNotReady IM断了
// onMessageReceived 收到推送的单聊、群聊、群提示、群系统通知的新消息
// im断开链接时
const onSdkNotReady = function(event) {
console.log('IM断了')
var islogin = storage.getVlogUserInfo();
if (islogin != null) {
// 重新执行IM登录
loginIm()
}
}
const onMessageReceived = function(event) {
// event.data - 存储 Message 对象的数组 - [Message]
// 这里处理消息通知相关业务4.0版本后续进行开发
console.log('收到了消息通知内容')
console.log(event.data)
}
const pushClick = (res) => {
console.log('notification clicked', res);
// 解析扩展信息,跳转到相应的会话(代码仅供参考,发布前需要完善)
try {
const data = JSON.parse(res.data);
const conv_type = data?.entity?.chatType === 1 ? 'C2C' : 'GROUP';
// 根据推送信息拼的 conversationID
const conversationID = `${conv_type}${data.entity.sender}`;
// 切换会话
TUIConversationService.switchConversation(conversationID);
const chatPath = '/TUIKit/components/TUIChat/index';
uni.navigateTo({
url: chatPath
});
} catch (error) {
console.log('error', error);
}
}
const pushOnLine = (res) => {
// res 为消息内容
console.log('在线推送', res);
}
const pushMsgBack = (res) => {
// res 为被撤回的消息 ID
console.log('撤回消息推送', res);
}
export const loginIm = () => {
console.log('执行im登录')
getUserimInfo()
.then(({
data
}) => {
console.log(data)
if (data.code == 200) {
const par = data.result;
TUILogin.login({
SDKAppID: par.sdkAppId,
userID: par.userID,
userSig: par.userSig,
useUploadPlugin: true, // If you need to send rich media messages, please set to true.
framework: `vue2` // framework used vue2 / vue3
}).then((res) => {
var {
SDKAppID,
userID,
userSig,
chat
} = TUILogin.getContext();
getApp().globalData.chat = chat;
console.log('我是个老板', res)
// 每次登录先移除,避免多次监听
chat.off('sdkStateNotReady', onSdkNotReady);
chat.off('onMessageReceived', onMessageReceived);
// 监听im断开链接后重新链接
chat.on('sdkStateNotReady', onSdkNotReady);
// 监听消息通知
chat.on('onMessageReceived', onMessageReceived);
Push.setRegistrationID(par.userID, () => {
console.log('设置id设置id设置id设置id设置id设置id设置id设置id设置id设置id', par.userID);
Push.registerPush(
par.sdkAppId,
'vkFpe55aYqfV7Sk5uGaoxhEstJ3tcI9dquk7JwG1GloDSLD2HeMWeQweWWXgNlhC',
(data) => {
console.log('registerPush ok', data);
Push.getRegistrationID((registrationID) => {
console.log('getRegistrationID ok',
registrationID);
});
},
(errCode, errMsg) => {
console.error('registerPush failed', errCode, errMsg);
}
);
});
// 监听通知栏点击事件,获取推送扩展信息
Push.addPushListener(Push.EVENT.NOTIFICATION_CLICKED, pushClick);
// 监听在线推送
Push.addPushListener(Push.EVENT.MESSAGE_RECEIVED, pushOnLine);
// 监听在线推送被撤回
Push.addPushListener(Push.EVENT.MESSAGE_REVOKED, pushMsgBack);
});
} else {
// 接口返回非 200 状态码,跳转登录页面
uni.navigateTo({
url: '/pages/passport/login'
});
}
})
.catch((e) => {
console.log(e)
});
}
export const clearIm = async () => {
var chat = getApp().globalData.chat;
var res_out = await chat.logout()
console.log(res_out)
console.log('IM退出登录')
getApp().globalData.chat = null;
// chat.logout中做了关闭推送服务
// Push.unRegisterPush().then(res => {
// //反注册关闭推送服务
// console.log(res)
// console.log('反注册关闭推送服务')
// })
Push.removePushListener(Push.EVENT.NOTIFICATION_CLICKED, pushClick)
Push.removePushListener(Push.EVENT.MESSAGE_RECEIVED, pushOnLine)
Push.removePushListener(Push.EVENT.MESSAGE_REVOKED, pushMsgBack)
}
export const conversationData = async () => {
// 会话列表
try {
const chatInstance = getApp().globalData.chat
console.log(chatInstance)
var res = await chatInstance.getConversationList()
return res
} catch (err) {
console.log(err)
}
}
export const sendVlogCustomMsg = async (i, vlogItem) => {
// i=IM相关用户信息
console.log(i);
console.log(vlogItem);
try {
var chat = getApp().globalData.chat;
var conversationType = i.type;
if (conversationType == 'C2C') {
var to = i.userProfile.userID;
} else {
var to = i.groupProfile.groupID;
}
var message = chat.createCustomMessage({
to,
conversationType,
payload: {
data: JSON.stringify({
businessID: 'video',
title: vlogItem.vlogerName,
description: vlogItem.content,
price: '分享好视频',
link: '/pages/me/vlog?vlogId=' + vlogItem.vlogId,
imageUrl: vlogItem.cover || vlogItem.firstFrameImg
}),
description: '[分享视频]',
extension: '',
},
cloudCustomData: JSON.stringify({
pushTitle: vlogItem.vlogerName,
pushDesc: vlogItem.content,
businessID: 'video', // 保持一致
})
})
var result = await chat.sendMessage(message)
console.log('发送成功:', result);
return result; // 成功就把发送结果返回出去
} catch (err) {
console.log(err);
throw err;
}
}

View File

@ -11,6 +11,12 @@ import api from "@/config/api.js";
import uuid from "@/utils/uuid.modified.js"; import uuid from "@/utils/uuid.modified.js";
import {
clearIm
} from "@/utils/handleim.js";
function cleanStorage() { function cleanStorage() {
uni.showToast({ uni.showToast({
title: "你的登录状态已过期,请重新登录", title: "你的登录状态已过期,请重新登录",
@ -30,7 +36,10 @@ function cleanStorage() {
storage.setVlogToken(""); storage.setVlogToken("");
storage.setVlogUserInfo(null); storage.setVlogUserInfo(null);
// 清除初始化数据内容 // 清除初始化数据内容
storage.setRefreshVlogIndex("0"); //不需要刷新 storage.setRefreshVlogIndex("1"); //需要刷新
// 退出im登录
clearIm()
// 获取当前页面栈 // 获取当前页面栈
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
@ -38,12 +47,16 @@ function cleanStorage() {
// 防抖处理跳转 // 防抖处理跳转
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
if (currentRoute !== 'pages/passport/wechatMPLogin') { if (currentRoute !== 'pages/passport/wechatMPLogin') {
uni.navigateTo({ url: "/pages/passport/wechatMPLogin" }); uni.navigateTo({
url: "/pages/passport/wechatMPLogin"
});
} }
// #endif // #endif
// #ifndef MP-WEIXIN // #ifndef MP-WEIXIN
if (currentRoute !== 'pages/passport/login') { if (currentRoute !== 'pages/passport/login') {
uni.navigateTo({ url: "/pages/passport/login" }); uni.navigateTo({
url: "/pages/passport/login"
});
} }
// #endif // #endif
} }
@ -117,18 +130,26 @@ let requests = [];
http.interceptors.response.use( http.interceptors.response.use(
async (response) => { async (response) => {
// console.log(isRefreshing) // console.log(isRefreshing)
// console.log(response) console.log(response)
/* 请求之后拦截器。可以使用async await 做异步操作 */ /* 请求之后拦截器。可以使用async await 做异步操作 */
// token存在并且token过期 // token存在并且token过期
if (isRefreshing && response.statusCode === 403) {
cleanStorage(); /**
isRefreshing = false; * 后续进来的请求此时异步获取token时isRefreshing一定为true
} * 那么也就代表此时token一定是过期状态响应码也一定为403
* 也就会去清理缓存
* 所以会导致页面多次刷新到登录页
*/
// if (isRefreshing && response.statusCode === 403) {
// cleanStorage();
// isRefreshing = false;
// }
let token = storage.getAccessToken(); let token = storage.getAccessToken();
if ( if (
(token && response.statusCode === 403) || (token && response.statusCode === 403) ||
response.data.status === 403 (token && response.data.status === 403)
) { ) {
if (!isRefreshing) { if (!isRefreshing) {
isRefreshing = true; isRefreshing = true;
@ -149,6 +170,8 @@ http.interceptors.response.use(
return http.request(response.config); return http.request(response.config);
}) })
.catch((err) => { .catch((err) => {
console.log('刷新token失败刷新token失败刷新token失败刷新token失败刷新token失败刷新token失败')
console.log(err);
cleanStorage(); cleanStorage();
return Promise.reject(err); return Promise.reject(err);
}) })
@ -160,17 +183,19 @@ http.interceptors.response.use(
return new Promise((resolve) => { return new Promise((resolve) => {
// 用函数形式将 resolve 存入,等待刷新后再执行 // 用函数形式将 resolve 存入,等待刷新后再执行
requests.push((token) => { requests.push((token) => {
// 刷新token后传入新的token
response.header.accessToken = `${token}`; response.header.accessToken = `${token}`;
resolve(http.request(response.config)); resolve(http.request(response.config));
}); });
}); });
} }
// 如果当前返回没登录 // 这是没有token的情况
} else if ( } else if (
(!token && response.statusCode === 403) || (!token && response.statusCode === 403) ||
response.data.code === 403 response.data.code === 403
) { ) {
console.log('没有token的情况');
cleanStorage(); cleanStorage();
// 如果当前状态码为正常但是success为不正常时 // 如果当前状态码为正常但是success为不正常时
@ -180,7 +205,8 @@ http.interceptors.response.use(
) { ) {
if (response.data.message) { if (response.data.message) {
uni.showToast({ uni.showToast({
title: response.data.message, // title: response.data.message,
title: "请重试",
icon: "none", icon: "none",
duration: 1500, duration: 1500,
}); });