Эх сурвалжийг харах

迁移wx小程序评审代码到独立分支

blue 1 жил өмнө
parent
commit
1768e460a8

+ 17 - 0
im-uniapp/App.vue

@@ -15,6 +15,8 @@
 			init() {
 				// 加载数据
 				store.dispatch("load").then(() => {
+					// 审核
+					this.initAudit();
 					// 初始化websocket
 					this.initWebSocket();
 				}).catch((e) => {
@@ -239,6 +241,21 @@
 				// this.audioTip = uni.createInnerAudioContext();
 				// this.audioTip.src =  "/static/audio/tip.wav";
 				// this.audioTip.play();
+			},
+			initAudit() {
+				if (store.state.userStore.userInfo.type == 1) {
+					// 显示群组功能
+					uni.setTabBarItem({
+						index: 2,
+						text: "群聊"
+					})
+				} else {
+					// 隐藏群组功能
+					uni.setTabBarItem({
+						index: 2,
+						text: "搜索"
+					})
+				}
 			}
 		},
 		onLaunch() {

+ 118 - 0
im-uniapp/components/user-search/user-search.vue

@@ -0,0 +1,118 @@
+<template>
+	<!-- for wx audit -->
+	<view class="page user-search">
+		<view class="search-bar">
+			<uni-search-bar v-model="searchText" :focus="true" @confirm="onSearch()" can
+				cancelButton="none" ceholder="用户名/昵称"></uni-search-bar>
+		</view>
+		<view class="user-items">
+			<scroll-view class="scroll-bar" scroll-with-animation="true" scroll-y="true">
+				<view v-for="(user) in users" :key="user.id" v-show="user.id != $store.state.userStore.userInfo.id">
+					<view class="user-item">
+						<head-image :id="user.id" :name="user.nickName" 
+							:online="user.online" :url="user.headImage"
+							:size="100"></head-image>
+						<view class="user-name">{{ user.nickName}}</view>
+						<view class="user-btns">
+							<button type="primary" v-show="!isFriend(user.id)" size="mini"
+								@click.stop="onAddFriend(user)">加为好友</button>
+							<button type="default" v-show="isFriend(user.id)" size="mini" disabled>已添加</button>
+						</view>
+					</view>
+				</view>
+			</scroll-view>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				searchText: "",
+				users: []
+			}
+		},
+		methods: {
+			onSearch() {
+				this.$http({
+					url: "/user/findByName?name=" + this.searchText,
+					method: "GET"
+				}).then((data) => {
+					this.users = data;
+				})
+			},
+			onAddFriend(user) {
+				this.$http({
+					url: "/friend/add?friendId=" + user.id,
+					method: "POST"
+				}).then((data) => {
+					let friend = {
+						id: user.id,
+						nickName: user.nickName,
+						headImage: user.headImage,
+						online: user.online
+					}
+					this.$store.commit("addFriend", friend);
+					uni.showToast({
+						title: "添加成功,对方已成为您的好友",
+						icon: "none"
+					})
+				})
+			},
+			onShowUserInfo(user) {
+				uni.navigateTo({
+					url: "/pages/common/user-info?id=" + user.id
+				})
+			},
+			isFriend(userId) {
+				let friends = this.$store.state.friendStore.friends;
+				let friend = friends.find((f) => f.id == userId);
+				return friend&&!friend.delete;
+			}
+		}
+	}
+</script>
+
+<style scoped lang="scss">
+	.user-search {
+		position: relative;
+		border: #dddddd solid 1px;
+		display: flex;
+		flex-direction: column;
+
+		.search-bar {
+			background: white;
+		}
+		.user-items{
+			position: relative;
+			flex: 1;
+			overflow: hidden;
+			.user-item {
+				height: 120rpx;
+				display: flex;
+				margin-bottom: 1rpx;
+				position: relative;
+				padding: 0 30rpx ;
+				align-items: center;
+				background-color: white;
+				white-space: nowrap;
+			
+				.user-name {
+					flex:1;	
+					padding-left: 20rpx;
+					font-size: 30rpx;
+					font-weight: 600;
+					line-height: 60rpx;
+					white-space: nowrap;
+					overflow: hidden;
+				}
+			}
+			
+			.scroll-bar {
+				height: 100%;
+			}
+		}
+		
+	}
+</style>

+ 1 - 1
im-uniapp/pages.json

@@ -61,7 +61,7 @@
 				"pagePath": "pages/group/group",
 				"iconPath": "static/tarbar/group.png",
 				"selectedIconPath": "static/tarbar/group_active.png",
-				"text": "群聊"
+				"text": "搜索"
 			},
 			{
 				"pagePath": "pages/mine/mine",

+ 5 - 1
im-uniapp/pages/group/group.vue

@@ -1,5 +1,5 @@
 <template>
-	<view class="tab-page group">
+	<view v-if="$store.state.userStore.userInfo.type == 1" class="tab-page group">
 		<view class="nav-bar">
 			<view class="nav-search">
 				<uni-search-bar @focus="onFocusSearch" cancelButton="none" placeholder="点击搜索群聊"></uni-search-bar>
@@ -19,6 +19,10 @@
 			</scroll-view>
 		</view>
 	</view>
+	<!-- wx audit -->
+	<view v-else>
+		<user-search></user-search>
+	</view>
 </template>
 
 <script>