Browse Source

接口

master
chenlong 2 years ago
parent
commit
c2fd4c88ba
  1. 17
      api/chat.js
  2. 20
      api/order.js
  3. 15
      api/pet.js
  4. 174
      pages/ChatDetail/index.vue
  5. 11
      pages/FeedLog/index.vue
  6. 22
      pages/Index/components/ChatPage/index.vue
  7. 18
      pages/Index/components/OrderPage/index.vue
  8. 111
      unpackage/dist/dev/mp-weixin/pages/ChatDetail/index.js
  9. 2
      unpackage/dist/dev/mp-weixin/pages/ChatDetail/index.wxml
  10. 24
      unpackage/dist/dev/mp-weixin/pages/Index/components/ChatPage/Index.js
  11. 19
      unpackage/dist/dev/mp-weixin/pages/Index/components/OrderPage/Index.js
  12. 5
      utils/request.js

17
api/chat.js

@ -16,4 +16,21 @@ export function chatList(page, is_worker){
is_worker: is_worker
}
})
}
/**
* 获取聊天token
* @param order_service_id 订单ID
* @param user_sign 用户类型1 用户 2 服务人员
* @returns {Promise | Promise<unknown>}
*/
export function getToken(order_service_id, user_sign){
return request({
url:'/user/chat-token',
method:"post",
data:{
order_service_id:order_service_id,
type:user_sign
}
})
}

20
api/order.js

@ -15,4 +15,24 @@ export function cardOrder(card_id)
card_id
}
})
}
/**
* 订单列表
* @param data
* @returns {Promise<unknown>}
*/
export function getOrderList(data = {
"page": 1,
"limit": 10,
"is_worker": 0,
"status": 0,
"start_time": "",
"end_time": ""
}){
return request({
url:"pet/order-list",
method: 'post',
data:data
})
}

15
api/pet.js

@ -30,4 +30,19 @@ export function getDetail(id){
id
}
})
}
/**
* 喂养档案
* @param pet_id
* @returns {Promise<unknown>}
*/
export function feedLog(pet_id){
return request({
url:'pet/feed-info',
method:'post',
data:{
pet_id
}
})
}

174
pages/ChatDetail/index.vue

@ -6,66 +6,58 @@
<view class="app-wallpaper">
<view class="detail-container" :style="{height:windowHeihgt-40+'px'}">
<view class="detail-content-container">
<view class="detail-content">
<view class="chat-item other-chat row">
<view class="detail-content" style="height: calc(100%);overflow: auto;padding-bottom: 150px;box-sizing: border-box;">
<view :class="item.send_user_id === user_id ? 'chat-item my-chat row' : 'chat-item other-chat row'" v-for="(item, index) in messageList" wx:key="index">
<view class="chat-item-content row">
<view class="chat-avator ">
<image mode="aspectFill" class="img" :src="user.avatar" />
<view class="chat-avator " v-if="item.send_user_id !== user_id">
<image mode="aspectFill" class="img" :src="item.avatar ? item.avatar : user.avatar" />
</view>
<view class="chat-content-container ">
<view class="chat-time">2023/06/16 13:24</view>
<view class="chat-content">是按您预约时间上门服务吗</view>
<view class="chat-time">{{ item.create_time }}</view>
<view class="chat-content">{{ item.info }}</view>
</view>
</view>
</view>
<view class="chat-item my-chat row">
<view class="chat-item-content row">
<view class="chat-content-container ">
<view class="chat-time">2023/06/16 13:24</view>
<view class="chat-content">是的您按预约时间上门就可以了</view>
</view>
<view class="chat-avator ">
<image mode="aspectFill" class="img" :src="user.avatar" />
</view>
</view>
</view>
<view class="chat-item other-chat row">
<view class="chat-item-content row">
<view class="chat-avator ">
<image mode="aspectFill" class="img" :src="user.avatar" />
</view>
<view class="chat-content-container ">
<view class="chat-time">2023/06/16 13:24</view>
<view class="chat-content">好的您家狗狗脾气如何呀</view>
<view class="chat-avator " v-if="item.send_user_id === user_id">
<image mode="aspectFill" class="img" :src="item.avatar ? item.avatar : user.avatar" />
</view>
</view>
</view>
<!-- <view class="chat-item other-chat row">-->
<!-- <view class="chat-item-content row">-->
<!-- <view class="chat-avator ">-->
<!-- <image mode="aspectFill" class="img" :src="user.avatar" />-->
<!-- </view>-->
<!-- <view class="chat-content-container ">-->
<!-- <view class="chat-time">2023/06/16 13:24</view>-->
<!-- <view class="chat-content">好的您家狗狗脾气如何呀</view>-->
<!-- </view>-->
<!-- </view>-->
<!-- </view>-->
<view class="chat-item my-chat row">
<view class="chat-item-content row">
<view class="chat-content-container ">
<view class="chat-time">2023/06/16 13:24</view>
<view class="chat-content">狗狗脾气很好不用担心</view>
</view>
<view class="chat-avator ">
<image mode="aspectFill" class="img" :src="user.avatar" />
</view>
</view>
</view>
<!-- <view class="chat-item my-chat row">-->
<!-- <view class="chat-item-content row">-->
<!-- <view class="chat-content-container ">-->
<!-- <view class="chat-time">2023/06/16 13:24</view>-->
<!-- <view class="chat-content">狗狗脾气很好不用担心</view>-->
<!-- </view>-->
<!-- <view class="chat-avator ">-->
<!-- <image mode="aspectFill" class="img" :src="user.avatar" />-->
<!-- </view>-->
<!-- </view>-->
<!-- </view>-->
</view>
<view class="detail-input-group-container">
<view class="detail-input-group row">
<input class="detail-input" type="text"/>
<MzButton
title="发送"
font-color="#fff"
button-color="#4DC3B8"
button-width="auto"
class="detail-input-button">
</MzButton>
<input class="detail-input" v-model="message" type="text"/>
<view @click="sendMessage">
<MzButton
title="发送"
font-color="#fff"
button-color="#4DC3B8"
button-width="auto"
class="detail-input-button">
</MzButton>
</view>
</view>
</view>
</view>
@ -80,10 +72,12 @@
<script>
import {
imghost
} from '../../config/host.js'
} from '@/config/host'
import api from '../../utils/functions.js';
import HeaderNav from '../../components/HeaderNav/Index.vue';
import MzButton from '../../components/MzButton/Index.vue';
import {getToken} from "@/api/chat";
import log from "@/utils/log";
export default {
components: {
HeaderNav,
@ -104,17 +98,97 @@
id: 88685,
birthday: '2002-05-11',
},
ableChat: false,
message:'',
chat_id:0,
type:0,
user_id:0,
messageList:[]
},
onLoad() {
this.getToken();
},
methods: {
getToken(){
getToken(5, 1).then(data => {
this.chat_id = data.data.chat_id;
this.type = data.data.type;
this.user_id = data.data.user_id;
uni.connectSocket({
url: data.data.chat_url
});
uni.onSocketOpen( (res) => {
this.ableChat = true;
console.log('WebSocket连接已打开!');
});
uni.onSocketClose((res) => {
this.ableChat = false;
console.log('WebSocket 已关闭!');
});
uni.onSocketMessage((res) => {
this.newMessage(res);
})
})
},
newMessage(messages){
log(messages);
messages = JSON.parse(messages.data);
log(messages);
if (messages.do_type === 'init'){
this.messageList = messages.data;
return;
}
this.messageList.push(messages);
log(this.messageList);
},
sendMessage(){
if (!this.message){
return uni.showToast({
title:"消息不能为空",
icon:'error'
})
}
uni.showLoading({
title: '消息发送中...',
mask:true,
});
if (!this.ableChat) {
setInterval((t) =>{
if (!this.ableChat) {
return;
}
clearInterval(t);
uni.sendSocketMessage({
data:this.message
});
uni.hideLoading();
}, 50);
}else{
uni.sendSocketMessage({
data:JSON.stringify({
do_type:'add',
info:this.message,
msg_type:1,
send_user_id:this.user_id,
type:this.type,
chat_id:this.chat_id,
})
});
uni.hideLoading();
}
}
},
onPageScroll(res) {
},
onUnload() {
try{
uni.closeSocket();
}catch{}
},
created() {
this.windowHeihgt = api.navHeight().windowHeihgt;

11
pages/FeedLog/index.vue

@ -206,6 +206,7 @@
import RightNav from '@/components/RightNav/Index.vue';
import MzButton from '@/components/MzButton/Index.vue';
import api from '@/utils/functions.js';
import {feedLog} from "@/api/pet";
export default {
components: {
HeaderNav,
@ -226,11 +227,12 @@
addPet:imghost +'/static/image/add-pet.png',
banner:imghost +'/static/image/banner.png',
feedUpload:imghost +'/static/image/feed-upload.png',
detail:{},
},
}
},
onLoad() {
onLoad(options) {
this.feedLog(options.pet_id)
},
methods: {
navTo(url){
@ -238,6 +240,11 @@
url:url
})
},
feedLog(pet_id){
feedLog(pet_id).then(data => {
this.detail = data.data
})
}
},
onPageScroll(res) {
if(res.scrollTop <= 20){

22
pages/Index/components/ChatPage/index.vue

@ -69,27 +69,7 @@
id: 88685,
},
isTop: false,
chatList:[
{
id:1,
avatar:'成都市武侯区丰德国际4栋...',
title:'2023.05.06订单',
desc:'需要您带一点猫砂上门,谢谢',
time:'2023/06/16',
},{
id:2,
avatar:'成都市武侯区丰德国际4栋...',
title:'2023.05.06订单',
desc:'需要您带一点猫砂上门,谢谢',
time:'2023/06/16',
},{
id:3,
avatar:'成都市武侯区丰德国际4栋...',
title:'2023.05.06订单',
desc:'需要您带一点猫砂上门,谢谢',
time:'2023/06/16',
},
]
chatList:[]
}
},
mounted() {

18
pages/Index/components/OrderPage/index.vue

@ -100,6 +100,8 @@
import RightNav from '@/components/RightNav/Index.vue';
import MzButton from '@/components/MzButton/Index.vue';
import api from '@/utils/functions.js';
import {getOrderList} from "@/api/order";
import log from "@/utils/log";
export default {
components: {
HeaderNav,
@ -154,6 +156,19 @@
url:url
})
},
getOrderList(page = 1, filter = {
status: "",
start_time: "",
end_time: ""
}){
filter.is_worker = this.$store.state.userInfo.store_id ? 1 : 0;
filter.page = page;
filter.limit = 10;
getOrderList(filter).then(data => {
log(data);
})
}
},
onPageScroll(res) {
if(res.scrollTop <= 20){
@ -162,6 +177,9 @@
uni.$emit('isTop', false);
}
},
mounted() {
this.getOrderList();
},
created() {
this.pagePadding = (api.navHeight().navPaddingTop +
api.navHeight().navHeight + (api.navHeight().headerPadding * 2))

111
unpackage/dist/dev/mp-weixin/pages/ChatDetail/index.js vendored

@ -1,9 +1,11 @@
"use strict";
const common_vendor = require("../../common/vendor.js");
const config_host = require("../../config/host.js");
const utils_functions = require("../../utils/functions.js");
const common_vendor = require("../../common/vendor.js");
require("../../utils/log.js");
const api_chat = require("../../api/chat.js");
const utils_log = require("../../utils/log.js");
require("../../utils/qqmap-wx-jssdk.min.js");
require("../../utils/request.js");
const HeaderNav = () => "../../components/HeaderNav/Index.js";
const MzButton = () => "../../components/MzButton/Index.js";
const _sfc_main = {
@ -25,16 +27,95 @@ const _sfc_main = {
coupons: 221,
id: 88685,
birthday: "2002-05-11"
}
},
ableChat: false,
message: "",
chat_id: 0,
type: 0,
user_id: 0,
messageList: []
},
onLoad() {
this.getToken();
},
methods: {
getToken() {
api_chat.getToken(5, 1).then((data) => {
this.chat_id = data.data.chat_id;
this.type = data.data.type;
this.user_id = data.data.user_id;
common_vendor.index.connectSocket({
url: data.data.chat_url
});
common_vendor.index.onSocketOpen((res) => {
this.ableChat = true;
console.log("WebSocket连接已打开!");
});
common_vendor.index.onSocketClose((res) => {
this.ableChat = false;
console.log("WebSocket 已关闭!");
});
common_vendor.index.onSocketMessage((res) => {
this.newMessage(res);
});
});
},
newMessage(messages) {
utils_log.log(messages);
messages = JSON.parse(messages.data);
utils_log.log(messages);
if (messages.do_type === "init") {
this.messageList = messages.data;
return;
}
this.messageList.push(messages);
utils_log.log(this.messageList);
},
sendMessage() {
if (!this.message) {
return common_vendor.index.showToast({
title: "消息不能为空",
icon: "error"
});
}
common_vendor.index.showLoading({
title: "消息发送中...",
mask: true
});
if (!this.ableChat) {
setInterval((t) => {
if (!this.ableChat) {
return;
}
clearInterval(t);
common_vendor.index.sendSocketMessage({
data: this.message
});
common_vendor.index.hideLoading();
}, 50);
} else {
common_vendor.index.sendSocketMessage({
data: JSON.stringify({
do_type: "add",
info: this.message,
msg_type: 1,
send_user_id: this.user_id,
type: this.type,
chat_id: this.chat_id
})
});
common_vendor.index.hideLoading();
}
}
},
onPageScroll(res) {
},
onUnload() {
try {
common_vendor.index.closeSocket();
} catch {
}
},
created() {
this.windowHeihgt = utils_functions.api.navHeight().windowHeihgt;
}
@ -51,16 +132,30 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
["is-back"]: true
}),
b: "url(" + _ctx.staticImage.wallpaperBgImage + ")",
c: _ctx.user.avatar,
d: _ctx.user.avatar,
e: _ctx.user.avatar,
f: _ctx.user.avatar,
g: common_vendor.p({
c: common_vendor.f(_ctx.messageList, (item, index, i0) => {
return common_vendor.e({
a: item.send_user_id !== _ctx.user_id
}, item.send_user_id !== _ctx.user_id ? {
b: item.avatar ? item.avatar : _ctx.user.avatar
} : {}, {
c: common_vendor.t(item.create_time),
d: common_vendor.t(item.info),
e: item.send_user_id === _ctx.user_id
}, item.send_user_id === _ctx.user_id ? {
f: item.avatar ? item.avatar : _ctx.user.avatar
} : {}, {
g: common_vendor.n(item.send_user_id === _ctx.user_id ? "chat-item my-chat row" : "chat-item other-chat row")
});
}),
d: _ctx.message,
e: common_vendor.o(($event) => _ctx.message = $event.detail.value),
f: common_vendor.p({
title: "发送",
["font-color"]: "#fff",
["button-color"]: "#4DC3B8",
["button-width"]: "auto"
}),
g: common_vendor.o((...args) => $options.sendMessage && $options.sendMessage(...args)),
h: _ctx.windowHeihgt - 40 + "px"
};
}

2
unpackage/dist/dev/mp-weixin/pages/ChatDetail/index.wxml vendored

@ -1 +1 @@
<header-nav wx:if="{{a}}" u-i="2ed33194-0" bind:__l="__l" u-p="{{a}}"></header-nav><view class="body-background" style="{{'background-image:' + b}}"></view><view class="app-wallpaper"><view class="detail-container" style="{{'height:' + h}}"><view class="detail-content-container"><view class="detail-content"><view class="chat-item other-chat row"><view class="chat-item-content row"><view class="chat-avator"><image mode="aspectFill" class="img" src="{{c}}"/></view><view class="chat-content-container"><view class="chat-time">2023/06/16 13:24</view><view class="chat-content">是按您预约时间上门服务吗</view></view></view></view><view class="chat-item my-chat row"><view class="chat-item-content row"><view class="chat-content-container"><view class="chat-time">2023/06/16 13:24</view><view class="chat-content">是的,您按预约时间上门就可以了</view></view><view class="chat-avator"><image mode="aspectFill" class="img" src="{{d}}"/></view></view></view><view class="chat-item other-chat row"><view class="chat-item-content row"><view class="chat-avator"><image mode="aspectFill" class="img" src="{{e}}"/></view><view class="chat-content-container"><view class="chat-time">2023/06/16 13:24</view><view class="chat-content">好的,您家狗狗脾气如何呀</view></view></view></view><view class="chat-item my-chat row"><view class="chat-item-content row"><view class="chat-content-container"><view class="chat-time">2023/06/16 13:24</view><view class="chat-content">狗狗脾气很好,不用担心</view></view><view class="chat-avator"><image mode="aspectFill" class="img" src="{{f}}"/></view></view></view></view><view class="detail-input-group-container"><view class="detail-input-group row"><input class="detail-input" type="text"/><mz-button wx:if="{{g}}" class="detail-input-button" u-i="2ed33194-1" bind:__l="__l" u-p="{{g}}"></mz-button></view></view></view><view class="detail-background-container"><view class="detail-background"></view></view></view></view>
<header-nav wx:if="{{a}}" u-i="2ed33194-0" bind:__l="__l" u-p="{{a}}"></header-nav><view class="body-background" style="{{'background-image:' + b}}"></view><view class="app-wallpaper"><view class="detail-container" style="{{'height:' + h}}"><view class="detail-content-container"><view class="detail-content" style="height:calc(100%);overflow:auto;padding-bottom:150px;box-sizing:border-box"><view wx:for="{{c}}" wx:for-item="item" class="{{item.g}}" wx:key="index"><view class="chat-item-content row"><view wx:if="{{item.a}}" class="chat-avator"><image mode="aspectFill" class="img" src="{{item.b}}"/></view><view class="chat-content-container"><view class="chat-time">{{item.c}}</view><view class="chat-content">{{item.d}}</view></view><view wx:if="{{item.e}}" class="chat-avator"><image mode="aspectFill" class="img" src="{{item.f}}"/></view></view></view></view><view class="detail-input-group-container"><view class="detail-input-group row"><input class="detail-input" type="text" value="{{d}}" bindinput="{{e}}"/><view bindtap="{{g}}"><mz-button wx:if="{{f}}" class="detail-input-button" u-i="2ed33194-1" bind:__l="__l" u-p="{{f}}"></mz-button></view></view></view></view><view class="detail-background-container"><view class="detail-background"></view></view></view></view>

24
unpackage/dist/dev/mp-weixin/pages/Index/components/ChatPage/Index.js vendored

@ -36,29 +36,7 @@ const _sfc_main = {
id: 88685
},
isTop: false,
chatList: [
{
id: 1,
avatar: "成都市武侯区丰德国际4栋...",
title: "2023.05.06订单",
desc: "需要您带一点猫砂上门,谢谢",
time: "2023/06/16"
},
{
id: 2,
avatar: "成都市武侯区丰德国际4栋...",
title: "2023.05.06订单",
desc: "需要您带一点猫砂上门,谢谢",
time: "2023/06/16"
},
{
id: 3,
avatar: "成都市武侯区丰德国际4栋...",
title: "2023.05.06订单",
desc: "需要您带一点猫砂上门,谢谢",
time: "2023/06/16"
}
]
chatList: []
};
},
mounted() {

19
unpackage/dist/dev/mp-weixin/pages/Index/components/OrderPage/Index.js vendored

@ -2,8 +2,10 @@
const common_vendor = require("../../../../common/vendor.js");
const config_host = require("../../../../config/host.js");
const utils_functions = require("../../../../utils/functions.js");
require("../../../../utils/log.js");
const api_order = require("../../../../api/order.js");
const utils_log = require("../../../../utils/log.js");
require("../../../../utils/qqmap-wx-jssdk.min.js");
require("../../../../utils/request.js");
const HeaderNav = () => "../../../../components/HeaderNav/Index.js";
const FooterNav = () => "../../../../components/FooterNav/Index.js";
const RightNav = () => "../../../../components/RightNav/Index.js";
@ -60,6 +62,18 @@ const _sfc_main = {
common_vendor.wx$1.navigateTo({
url
});
},
getOrderList(page = 1, filter = {
status: "",
start_time: "",
end_time: ""
}) {
filter.is_worker = this.$store.state.userInfo.store_id ? 1 : 0;
filter.page = page;
filter.limit = 10;
api_order.getOrderList(filter).then((data) => {
utils_log.log(data);
});
}
},
onPageScroll(res) {
@ -69,6 +83,9 @@ const _sfc_main = {
common_vendor.index.$emit("isTop", false);
}
},
mounted() {
this.getOrderList();
},
created() {
this.pagePadding = utils_functions.api.navHeight().navPaddingTop + utils_functions.api.navHeight().navHeight + utils_functions.api.navHeight().headerPadding * 2;
}

5
utils/request.js

@ -1,8 +1,13 @@
import functions from '@/utils/functions.js'
import {host} from "@/config/host";
const service = (params) => {
return new Promise((relove, reject) => {
let token=uni.getStorageSync('token')
let user=uni.getStorageSync('user')
if (!/^http/.test(params.url)){
params.url = `${host}/${params.url}`.replace(/(?<!:)\/{2,}/, '/')
}
uni.request({
url: params.url,
data: params.data,

Loading…
Cancel
Save