合并代码

This commit is contained in:
sx 2025-01-05 20:06:22 +08:00
parent 77ceacf2a5
commit 151d93a6d1
8 changed files with 280 additions and 163 deletions

View File

@ -1,60 +1,54 @@
<script>
<script setup>
import {
onLaunch,
} from '@dcloudio/uni-app'
//
import util from '@/common/js/util';
//
import api from '@/api/index.js'
// vuex
import store from '@/store/index.js'
// import Mixins from '@/utils/Mixins.js'
export default {
// mixins: [Mixins],
onLaunch() {
//
this.getUserinfo()
//
this.getConfig()
},
onLaunch(() => {
//
getUserinfo()
//
getConfig()
})
methods: {
//
getUserinfo() {
//
const token = uni.getStorageSync('token')
//
const userinfo = uni.getStorageSync('userinfo')
//
function getUserinfo() {
//
const token = uni.getStorageSync('token')
//
const userinfo = uni.getStorageSync('userinfo')
//
if (token) {
//
if (userinfo) store.commit('setState', {
key: 'userinfo',
value: userinfo
})
//
if (token) {
//
if (userinfo) store.commit('setState', {
key: 'userinfo',
value: userinfo
})
util.getUserinfo(() => {
// im
util.loginTencent(userinfo)
//
util.loginAccountManagement(userinfo)
})
}
},
//
getConfig() {
api.getConfig().then(rs => {
if(rs.code == 200) {
store.commit('setState', {
key: 'config',
value: rs.data
})
return
}
})
}
// im
util.loginTencent(userinfo)
util.getUserinfo()
}
}
//
function getConfig() {
api.getConfig().then(rs => {
if (rs.code == 200) {
store.commit('setState', {
key: 'config',
value: rs.data
})
return
}
})
}
</script>
<style lang="scss">

View File

@ -21,9 +21,9 @@ const config = {
// 腾讯im聊天
TChat: {
// appid
SDKAppID: '1600057470',
SDKAppID: '1600067241',
// 验签
secretKey: '7d016821bf27a846739e209534abe4c4bba131559b3318e19f8ccf9294e08b29',
secretKey: '955ac1c071050fe1ed0be74470409495cfb4faa5faf7c88ea58b585890433708',
//
userSig: '',
},

View File

@ -1431,11 +1431,6 @@ const util = {
util.getUserinfo((userinfo) => {
// 登录
uni.$emit('login')
// 腾讯im登录
util.loginTencent(userinfo)
// 储存登录账号
// util.loginAccountManagement(userinfo)
// return
setTimeout(() => {
uni.switchTab({
@ -1447,20 +1442,6 @@ const util = {
})
},
// 登录账号管理
loginAccountManagement(userInfo) {
// 取出本地保存的账号信息
let userList = uni.getStorageSync('userInfoList') || []
// 判断账号是否已存在 存在则删除后重新添加 否则添加
const index = userList.findIndex(item => item.userId === userInfo.userId)
if (index !== -1) {
userList.splice(index, 1)
}
userList.push(userInfo)
// 缓存
uni.setStorageSync('userInfoList', userList)
},
// 登录腾讯聊天
loginTencent(userinfo) {
api.login.getIMToken({}).then(rs => {
@ -1487,7 +1468,6 @@ const util = {
console.log('im login success', rs)
})
})
return
},
/**
@ -1499,13 +1479,7 @@ const util = {
// 请求接口
api.mine.getUserinfo().then(rs => {
if (rs.code === 200) {
// 用户信息
const userinfo = rs.data
// 处理头像
// userinfo.userPortrait = util.format_url(userinfo.userPortrait, 'img')
// 处理背景图
// userinfo.background = util.format_url(userinfo.background, 'img')
reslove(userinfo)
reslove(rs.data)
// 提交
store.commit('setState', {
key: 'userinfo',

View File

@ -705,6 +705,12 @@
"navigationBarBackgroundColor": "#fff"
}
},
{
"path": "pages/news/myQr",
"style": {
"navigationBarTitleText": "我的二维码"
}
},
{
"path" : "pages/mine/setting/secondPwd",
"style" :

View File

@ -0,0 +1,84 @@
<script setup>
//
import uQRCode from '@/common/js/uqrcode.js'
import {
ref,
reactive,
computed,
} from 'vue'
import {
useStore,
} from 'vuex'
import {
onLoad,
} from '@dcloudio/uni-app'
// vuex
const store = useStore()
//
const userinfo = computed(() => {
let result = store.state.userinfo
return result
})
//
const qrcodeSize = ref(300)
//
const qrUrl = ref('')
onLoad(() => {
init()
})
//
function init() {
uni.showLoading({
title: '二维码生成中',
mask: true
})
//
const content = {
key: 'user',
userId: userinfo.value.userId,
userNickname: userinfo.value.userNickname,
}
uQRCode.make({
canvasId: 'qrcode',
text: JSON.stringify(content),
size: qrcodeSize.value,
margin: 10,
success: res => {
qrUrl.value = res
console.log('qrcodeSrc ', qrUrl.value);
},
complete: () => {
uni.hideLoading()
}
})
}
</script>
<template>
<view class="app">
<!-- -->
<view class="container ver mtb30 mlr30 tac">
<!-- 二维码插件 width height设置宽高 -->
<canvas canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}" />
<view class="user mtb30 df aic">
<view class="avatar">
<image class="wh80 cir" :src="userinfo.userPortrait" mode="aspectFill" />
</view>
<view class="nickname f1 ml20 c333 f32">{{userinfo.userNickname}}</view>
</view>
<view class="hint mtb30 tac c999">扫一扫添加我为好友</view>
</view>
</view>
</template>
<style lang="scss">
//
</style>

View File

@ -3,6 +3,8 @@
* 新的朋友
*/
//
import TencentCloudChat from '@tencentcloud/chat';
//
import util from '@/common/js/util';
// api
@ -14,11 +16,12 @@
ref,
reactive,
computed,
getCurrentInstance,
nextTick
} from 'vue'
import {
onLoad,
onReachBottom,
onPullDownRefresh
onUnload,
} from '@dcloudio/uni-app'
// vuex
const store = useStore()
@ -34,73 +37,82 @@
pageSize: 10,
total: 0,
})
const keyword = ref('')
//
const friend = ref({})
//
const {
proxy
} = getCurrentInstance()
onLoad(() => {
getFriendList()
addListener()
})
onPullDownRefresh(() => {
getFriendList()
onUnload(() => {
offListener()
})
//
function addListener() {
let fn = function(event) {
getFriendList()
}
//
uni.$chat.on(TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED, fn)
}
//
function offListener() {
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED, () => {})
}
//
function agreeFriend(item) {
api.video.agreeFriend({
path: [userinfo.value.userId, item.userId],
query: {
friend.value = {
...item
}
//
proxy.$refs.friend.open()
}
}
//
function addFriendConfirm() {
//
uni.$chat.acceptFriendApplication({
userID: friend.value.userID,
remark: friend.value.remark || '',
type: TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD
}).then(rs => {
if (rs.code === 200) {
uni.showToast({
title: '同意成功',
icon: 'success',
duration: 1500
});
} else {
uni.showToast({
title: rs.msg,
icon: 'error',
duration: 1500
});
}
}).finally(() => {
//
proxy.$refs.friend.close()
})
}
//
function refuseFriend(item) {
api.video.refuseFriend({
path: [userinfo.value.userId, item.userId],
util.alert({
content: '确认拒绝好友?',
}).then(rs => {
if (rs.code === 200) {
uni.showToast({
title: '拒绝成功',
icon: 'success',
duration: 1500
});
} else {
uni.showToast({
title: rs.msg,
icon: 'error',
duration: 1500
});
}
if (!rs.confirm) return
//
uni.$chat.refuseFriendApplication({
userID: item.userID,
})
})
}
//
//
function getFriendList() {
uni.$chat.getFriendApplicationList().then(rs => {
if (rs.code === 0) {
console.log('rs', rs)
const result = rs.data
userList.data = result.friendApplicationList
userList.data = result.friendApplicationList.map(node => {
node.formatTime = util.formatTime('yyyy-MM-dd hh:mm', node.time)
return node
})
}
}).finally(() => {
uni.stopPullDownRefresh()
})
}
@ -111,10 +123,22 @@
function handleUser(item) {
uni.navigateTo({
url: util.setUrl('/pages/index/videoHome', {
userId: item.userId,
userId: item.userID,
})
})
}
//
function pushNickname() {
friend.value.remark = friend.value.nick
}
//
function myQr() {
uni.navigateTo({
url: '/pages/news/myQr'
})
}
</script>
<template>
@ -129,33 +153,66 @@
</navigator>
</view>
<view class="ptb20 plr25 c666 f28">最近添加</view>
<view class="rows ptb20 plr25 c666 f28">
<view class="">申请列表</view>
<view class="c999" @click="myQr">我的二维码</view>
</view>
<view class="listArea plr30 bfff">
<!-- -->
<view class="item rows ptb30 c333 f32" v-for="(item,index) in userList.data" :key="index" @click="handleUser(item)">
<view class="avatar fs0">
<image class="wh100 cir" :src="item.avatar" mode="aspectFill" />
<view class="item ptb30 c333 f32" v-for="(item,index) in userList.data" :key="index" @click="handleUser(item)">
<view class="rows">
<view class="avatar fs0">
<image class="wh100 cir" :src="item.avatar" mode="aspectFill" />
</view>
<view class="content f1 mlr20">
<view class="name">{{item.nick}}</view>
<view class="time mt10 c999 f22">{{item.formatTime}}</view>
</view>
<!-- 发给我的好友申请 -->
<view class="btns rows fs0" v-if="item.type == TencentCloudChat.TYPES.SNS_APPLICATION_SENT_TO_ME">
<view class="btn black plr20" @click.stop="agreeFriend(item)">同意</view>
<view class="btn cancel plr20 ml20" @click.stop="refuseFriend(item)">拒绝</view>
</view>
<!-- 我发起的好友申请 -->
<view class="btns rows fs0" v-else-if="item.type == TencentCloudChat.TYPES.SNS_APPLICATION_SENT_BY_ME">
<view class="c999">等待对方同意</view>
</view>
</view>
<view class="content f1 mlr20">
<view class="name">{{item.name}}</view>
<view class="time c999 f22">{{item.createTime}}</view>
</view>
<view class="btns rows fs0" v-if="item.friendState == 1">
<view class="btn black plr20" @click.stop="agreeFriend(item)">同意</view>
<view class="btn cancel plr20 ml20" @click.stop="refuseFriend(item)">拒绝</view>
</view>
<view class="result fs0 c999" v-else-if="item.friendState == 2">已拒绝</view>
<view class="result fs0 c999" v-else-if="item.friendState == 3">已同意</view>
<view class="mt20 c999 f28">招呼语{{item.wording}}</view>
</view>
</view>
<view class="mtb20 nomore" v-if="!userList.data[0]">暂无申请~</view>
<!-- 填充 -->
<view class="fill" style="height: 60rpx;"></view>
<!-- 设置备注 -->
<uni-popup ref="friend" type="center">
<view class="friendAlt popMid plr20 bfff">
<view class="header rows ptb30 f32">
<view class="">给用户 {{friend.nick}} 设置备注</view>
<uni-icons type="closeempty" @click="$refs.friend.close()" />
</view>
<view class="main mlr30">
<view class="txtplus ptb20 plr20 br10">
<input type="text" v-model="friend.remark" placeholder="好友备注" />
</view>
<view class=" mt10 c666 f28" @click="pushNickname">
<text class="push">填入</text>
<text>对方昵称</text>
</view>
<view class="btn lg bar black mtb30" @click="addFriendConfirm">确定</view>
</view>
</view>
</uni-popup>
</view>
</template>
@ -170,4 +227,18 @@
border-top: 1rpx solid #ddd;
}
}
//
.friendAlt {
//
.txtplus {
background-color: #eee;
}
//
.push {
color: #20D200;
}
}
</style>

View File

@ -84,39 +84,28 @@
//
function showActionSheet() {
/* {
//
label: '公开设置',
} */
uni.showActionSheet({
itemList: ['扫一扫', '添加好友', '发起群聊', '我的二维码', '设置'],
itemList: ['扫一扫', '添加好友', '发起群聊', '我的二维码'],
success: rs => {
switch (rs.tapIndex) {
case 0:
uni.scanCode({
success: (res) => {
console.log('扫描结果:' + res.result);
getUserInfos(res.result)
},
fail: (err) => {
console.error('扫描失败:' + err);
uni.showToast({
title: '扫描失败',
icon: 'none'
});
}
})
util.scan()
break;
case 1:
uni.navigateTo({
url: '/pages/news/addFriend'
// url: '/pages/news/newFriend'
})
// url: '/pages/news/addFriend'
url: '/pages/news/newFriend'
});
break;
case 2:
uni.navigateTo({
url: '/pages/news/group-chat/index'
})
});
break;
case 3:
uni.navigateTo({
url: '/pages/news/myQr'
});
break;
default:
break;

View File

@ -1,4 +1,3 @@
import {
defineConfig
} from 'vite';
@ -15,8 +14,8 @@ export default defineConfig({
changeOrigin: true,
},
"/user": {
// target: "http://192.168.1.241:8080",
target: "http://7fee92ac.r22.cpolar.top",
target: "http://192.168.1.241:8080",
// target: "http://7fee92ac.r22.cpolar.top",
changeOrigin: true,
},
"/coreplay": {
@ -28,8 +27,8 @@ export default defineConfig({
changeOrigin: true,
},
"/video": {
// target: "http://192.168.1.241:8080",
target: "http://7fee92ac.r22.cpolar.top",
target: "http://192.168.1.241:8080",
// target: "http://7fee92ac.r22.cpolar.top",
changeOrigin: true,
},
}