Init project

This commit is contained in:
lifizer
2023-09-20 21:49:33 +08:00
parent 85a5989c96
commit c9ceac9f37
710 changed files with 125705 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
<template>
<web-view :src="pdfPath"></web-view>
</template>
<script>
export default {
name: "pdf",
data() {
return {
pdfPath: ""
}
},
onLoad(options) {
this.pdfPath = options.path;
}
}
</script>
+374
View File
@@ -0,0 +1,374 @@
<template>
<view class="common-room">
<view class="main">
<view class="queue" :class="{'last':index+1===list.length}" v-for="(item,index) in list" :key="index">
<view class="datetime">{{ item.created_at }}</view>
<view class="service-box flex" v-if="item.user_type===1">
<image class="cover" :src="item.header || webUrl+'/20221114155314348118.png'"/>
<view class="text">
<view class="name one-t">{{ item.username }}</view>
<text class="msg" v-if="item.msg_type===0">{{ item.msg_content }}</text>
<view class="msg" v-if="item.msg_type===1">
<image class="img" :src="item.msg_content" @click="preview(item.msg_content)"></image>
</view>
</view>
</view>
<view class="customer-box flex jc-end" v-else>
<view class="text flex flex-col ai-end">
<view class="name one-t">{{ item.username }}</view>
<text class="msg" v-if="item.msg_type===0">{{ item.msg_content }}</text>
<view class="msg" v-if="item.msg_type===1">
<image class="img" :src="item.msg_content" @click="preview(item.msg_content)"></image>
</view>
</view>
<image class="cover" :src="item.header || webUrl+'/20221114155314348118.png'"/>
</view>
</view>
</view>
<view class="footer flex jc-between ai-end">
<image :src="webUrl+'/20221014095236624035.png'" @click="getUploadToken"></image>
<view class="input-box">
<textarea v-model="content" maxlength="150" :auto-height="true" :fixed="true" confirm-type="send"
@input="userInput" @confirm="userSend"/>
</view>
<button @click="userSend">发送</button>
</view>
</view>
</template>
<script>
import {userUnionId} from "@/api/public";
export default {
name: "room",
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
token: null,
unionId: null,
userInfo: null,
storeId: null,
merName: null,
uploadToken: null, //上传token
socketOpen: false,
socketTask: null,
socketMsgQueue: [],
roomId: null, //房间ID
content: "", //消息内容
list: [], //消息列表
}
},
onLoad(options) {
this.storeId = options.id;
this.merName = options.name;
if (this.merName!="undefined" && this.merName!="null") {
uni.setNavigationBarTitle({
title: this.merName
})
}
this.token = uni.getStorageSync("login_status");
this.userInfo = uni.getStorageSync("userInfo");
this.getUnionId();
},
onUnload() {
if (this.socketOpen) {
this.socketTask.close();
}
},
methods: {
getUnionId() {
userUnionId().then(res => {
if (res.success) {
this.unionId = res.data;
this.connectSocketInit();
}
});
},
getUploadToken() {
let that = this;
uni.request({
url: this.$SERVICE_API_URL + "/get-upload-token",
method: "POST",
success: ({data}) => {
if (data.status === "success") {
this.uploadToken = data.content;
uni.chooseImage({
count: 1, //数量
sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: (chooseImageRes) => {
const tempFilePaths = chooseImageRes.tempFilePaths;
uni.uploadFile({
url: 'https://up-z2.qiniup.com', //接口地址
filePath: tempFilePaths[0],
name: 'file',
formData: {
'token': that.uploadToken
},
success: (uploadFileRes) => {
// uni.showModal({
// title: that.uploadToken + ' ',
// content: uploadFileRes.data + ' ',
// showCancel: false
// })
let imgKey = JSON.parse(uploadFileRes.data).key;
if (imgKey.length > 0) {
let param = {
type: "msg",
user_type: 0,
unionid: that.unionId,
username: that.userInfo.nickname,
header: that.userInfo.avatar,
room_id: that.roomId,
msg_type: 1,
content: imgKey,
token: that.token
}
that.sendSocketMessage(JSON.stringify(param));
}
}
});
}
});
}
}
})
},
// 预览图片
preview(url) {
uni.previewImage({
urls: [url]
});
},
// 进入这个页面的时候创建websocket连接【整个页面随时使用】
connectSocketInit() {
// 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
this.socketTask = uni.connectSocket({
url: this.$SOCKET_URL,
success: () => {
}
})
uni.onSocketOpen(res => {
console.log('WebSocket连接已打开!', res);
this.socketOpen = true;
this.createRoom();
});
uni.onSocketError(err => {
console.log('WebSocket连接打开失败,请检查!', err);
});
uni.onSocketMessage(res => {
console.log('收到服务器内容:', res.data);
this.handleMessage(res.data);
});
uni.onSocketClose(res => {
console.log('WebSocket 已关闭!', res);
});
},
userInput(event) {
this.content = event.detail.value;
},
userSend() {
if (this.content.length === 0) return;
let param = {
type: "msg",
user_type: 0,
unionid: this.unionId,
username: this.userInfo.nickname,
header: this.userInfo.avatar,
room_id: this.roomId,
msg_type: 0,
content: this.content,
token: this.token
}
this.sendSocketMessage(JSON.stringify(param));
this.content = "";
},
createRoom() {
let param = {
type: "join",
user_type: 0,
unionid: this.unionId,
username: this.userInfo.nickname,
header: this.userInfo.avatar,
store_id: this.storeId
};
this.sendSocketMessage(JSON.stringify(param));
},
sendSocketMessage(msg) {
if (this.socketOpen) {
uni.sendSocketMessage({
data: msg,
success(res) {
console.log("消息发送成功", res,msg);
}
});
} else {
this.socketMsgQueue.push(msg);
}
},
handleMessage(str) {
let data = JSON.parse(str);
switch (data.type) {
case "room_id":
this.roomId = data.msg_content;
break;
case "service_join":
break;
case "leave":
break;
case "msg":
this.list.push(data.msg_content);
this.scrollLast();
break;
case "msg_history":
this.list = data.msg_content.concat(this.list);
this.scrollLast();
break;
default:
break;
}
},
scrollLast() {
setTimeout(() => {
uni.pageScrollTo({
selector: ".last .msg",
duration: 1
})
}, 50)
}
}
}
</script>
<style scoped lang="less">
.common-room {
min-height: 100vh;
background: #F5F5F5;
font-size: 26rpx;
line-height: 38rpx;
color: #333333;
view {
box-sizing: border-box;
}
.main {
padding: 0 32rpx 130rpx;
.datetime {
margin: 30rpx 0;
font-size: 22rpx;
line-height: 32rpx;
color: #999999;
text-align: center;
}
.cover {
width: 48rpx;
height: 48rpx;
border-radius: 50%;
}
.text {
width: 550rpx;
margin: 0 20rpx;
}
.name {
margin-bottom: 16rpx;
font-size: 22rpx;
line-height: 32rpx;
}
.msg {
display: inline-block;
max-width: 560rpx;
padding: 16rpx;
background: #FFFFFF;
font-weight: bold;
word-break: break-all;
word-wrap: break-word;
.img {
max-width: 214rpx;
max-height: 214rpx;
vertical-align: middle;
}
}
.service-box {
margin: 30rpx 0;
}
.customer-box {
margin: 30rpx 0;
}
}
.footer {
position: fixed;
bottom: 0;
width: 100vw;
padding: 30rpx 32rpx 28rpx;
border-radius: 24rpx 24rpx 0 0;
background: #FFFFFF;
image {
width: 64rpx;
height: 64rpx;
vertical-align: middle;
}
.input-box {
width: 472rpx;
min-height: 64rpx;
box-sizing: border-box;
padding: 18rpx 30rpx;
border-radius: 32rpx;
background: #F5F5F5;
textarea {
width: 100%;
}
}
button {
width: 120rpx;
height: 64rpx;
margin: 0;
border-radius: 32rpx;
background: #FD574B;
font-size: 28rpx;
color: #FFFFFF;
font-weight: bold;
}
}
}
</style>
+109
View File
@@ -0,0 +1,109 @@
<template>
<view class="common-roomLogs">
<view class="item flex" v-for="(item,index) in list" :key="index" @click="goRoom(item)"
v-if="list.length>0">
<image class="cover flex-0" :src="item.store_avatar || webUrl+'/20221114155314348118.png'"/>
<view>
<view class="flex jc-between ai-center">
<view class="name">{{ item.store_name }}</view>
<view class="datetime" v-if="item.last_msg">{{ item.last_msg.created_at }}</view>
</view>
<view class="sub one-t" v-if="item.last_msg">{{ item.last_msg.msg_type===0?item.last_msg.msg_content:'[图片]' }}</view>
</view>
</view>
<view class="v4-nodata" v-if="list.length===0">
<image src="@/static/images/img_nodata.png" mode="scaleToFill"/>
<view class="text">暂无数据</view>
</view>
</view>
</template>
<script>
import {userUnionId} from "@/api/public";
export default {
name: "roomLogs",
data() {
return {
webUrl:this.$VUE_APP_RESOURCES_URL,
unionId: null,
list: []
}
},
onShow() {
this.getUnionId();
},
methods: {
goRoom(item) {
uni.navigateTo({url: `/pkg_common/views/room?id=${item.store_id}&name=${item.store_name}`})
},
getUnionId() {
userUnionId().then(res => {
if (res.success) {
this.unionId = res.data;
this.fetchList();
}
});
},
fetchList() {
uni.request({
url: this.$SERVICE_API_URL + "/customer-chat-list",
method: "POST",
data: {unionid: this.unionId},
success: res => {
if (res.data.status_code === 200) {
this.list = res.data.content;
}
}
})
}
}
}
</script>
<style scoped lang="less">
.common-roomLogs {
min-height: 100vh;
box-sizing: border-box;
padding: 32rpx;
background: #F5F5F5;
.item {
margin-bottom: 24rpx;
padding: 28rpx 20rpx 24rpx;
border-radius: 8rpx;
background: #FFFFFF;
.cover {
width: 80rpx;
height: 80rpx;
margin-right: 18rpx;
border-radius: 50%;
}
.name {
font-size: 26rpx;
font-weight: bold;
line-height: 38rpx;
color: #333333;
}
.datetime {
font-size: 22rpx;
line-height: 32rpx;
color: #999999;
}
.sub {
width: 548rpx;
margin-top: 12rpx;
font-size: 24rpx;
line-height: 34rpx;
color: #666666;
}
}
}
</style>