更新小程序仓库
This commit is contained in:
+3888
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
||||
|
||||
function hostConfig(){
|
||||
const Hosts = {
|
||||
host_dev:'https://dev.hospital.applets.igandanyiyuan.com',
|
||||
img_dev: 'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static', //开发环境
|
||||
agree_dev:'https://img.applets.igandanyiyuan.com',
|
||||
host_prod:'https://prod.hospital.applets.igandanyiyuan.com',
|
||||
img_prod: 'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static', //线上环境
|
||||
agree_prod:'https://oss.prod.applets.igandanyiyuan.com',
|
||||
};
|
||||
const { envVersion } = wx.getAccountInfoSync().miniProgram;
|
||||
let imghost="";
|
||||
let host='';
|
||||
let agreehost='';
|
||||
let SECRETKEY='';
|
||||
let SDKAPPID='';
|
||||
switch (envVersion) {
|
||||
case 'develop': //开发环境
|
||||
// host =`${Hosts.host_prod}`;
|
||||
// imghost=`${Hosts.img_prod}`;
|
||||
// agreehost=`${Hosts.agree_prod}`
|
||||
host = `${Hosts.host_dev}`;
|
||||
imghost= `${Hosts.img_dev}`;
|
||||
agreehost= `${Hosts.agree_dev}`;
|
||||
SECRETKEY='fc45ab469ca632a700166973d87b3a6f56a855cb92d7cffb54e4d37135c097da';
|
||||
SDKAPPID='1400798221';
|
||||
break;
|
||||
case 'trial': //体验版环境
|
||||
// host =`${Hosts.host_prod}`;
|
||||
// imghost=`${Hosts.img_prod}`;
|
||||
// agreehost=`${Hosts.agree_prod}`
|
||||
host = `${Hosts.host_dev}`;
|
||||
imghost=`${Hosts.img_dev}`;
|
||||
agreehost=`${Hosts.agree_dev}`;
|
||||
SECRETKEY='fc45ab469ca632a700166973d87b3a6f56a855cb92d7cffb54e4d37135c097da';
|
||||
SDKAPPID='1400798221';
|
||||
break;
|
||||
case 'release':
|
||||
host =`${Hosts.host_prod}`;
|
||||
imghost=`${Hosts.img_prod}`;
|
||||
agreehost=`${Hosts.agree_prod}`;
|
||||
SECRETKEY='a5bcd8c583181cf004e9d91a47687d719d4b5d2a10ce33fbee95d587889447d8';
|
||||
SDKAPPID='1400796919';
|
||||
break;
|
||||
};
|
||||
return { host, imghost,agreehost,SECRETKEY,SDKAPPID};
|
||||
|
||||
}
|
||||
module.exports={
|
||||
hostConfig
|
||||
}
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
getCurrentPageUrl,
|
||||
getCurrentPageParam
|
||||
} from "./getUrl"
|
||||
function formatUrl(){
|
||||
let redirectUrl=getCurrentPageUrl();
|
||||
let options=getCurrentPageParam();
|
||||
let params="";
|
||||
let url='';
|
||||
for (const key in options) {
|
||||
if(params){
|
||||
params=params+'&'+key+'='+options[key];
|
||||
}else{
|
||||
params=params+key+'='+options[key];
|
||||
}
|
||||
};
|
||||
if(params){
|
||||
url=redirectUrl+"?"+params
|
||||
}else{
|
||||
url=redirectUrl
|
||||
}
|
||||
return encodeURIComponent(url);
|
||||
}
|
||||
module.exports={
|
||||
formatUrl
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*获取当前页url*/
|
||||
const getCurrentPageUrl=()=>{
|
||||
try {
|
||||
let pages = getCurrentPages() //获取加载的页面
|
||||
let currentPage = pages[pages.length-1]
|
||||
let url = currentPage.route
|
||||
//当前页面url
|
||||
return url
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
/*获取当前页参数*/
|
||||
const getCurrentPageParam=()=>{
|
||||
let pages = getCurrentPages() //获取加载的页面
|
||||
let currentPage = pages[pages.length-1] //获取当前页面的对象
|
||||
let options = currentPage.options //如果要获取url中所带的参数可以查看options
|
||||
return options
|
||||
}
|
||||
module.exports = {
|
||||
getCurrentPageUrl,
|
||||
getCurrentPageParam
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import TIM from '../lib/tim-wx-sdk';
|
||||
import TIMUploadPlugin from '../lib/tim-upload-plugin';
|
||||
import {lastSysMsg} from "../api/msg"
|
||||
import {imSign} from "../api/common"
|
||||
import {loginout} from "../api/personCenter"
|
||||
import {setBarData} from "./util"
|
||||
wx.$TUIKit=null;
|
||||
wx.$TUIKitTIM=null;
|
||||
let appglobal=null;
|
||||
function imLogin(app){
|
||||
appglobal=app;
|
||||
imSign().then(data=>{
|
||||
wx.$TUIKit = TIM.create({
|
||||
SDKAppID: appglobal.globalData.config.SDKAPPID,
|
||||
});
|
||||
//const userSig = genTestUserSig(this.globalData.config).userSig;
|
||||
wx.$chat_SDKAppID = appglobal.globalData.config.SDKAPPID;
|
||||
wx.$TUIKitTIM = TIM;
|
||||
|
||||
wx.$chat_userID = appglobal.globalData.config.userID;
|
||||
//wx.$chat_userSig = userSig;
|
||||
wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin });
|
||||
wx.$TUIKit.setLogLevel(0);
|
||||
wx.$chat_userSig =data;
|
||||
let USER_ID=wx.getStorageSync('USER_ID');
|
||||
if(USER_ID){
|
||||
wx.$TUIKit.login({
|
||||
userID: wx.getStorageSync('USER_ID'),
|
||||
userSig:data
|
||||
}).then(res=>{
|
||||
console.log("登录成功");
|
||||
}).catch(function(imError) {
|
||||
console.warn('login error:', imError); // 登录失败的相关信息
|
||||
});
|
||||
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.SDK_READY,onSDKReady,this);
|
||||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.SDK_READY,onSDKReady);
|
||||
}else{
|
||||
console.log("IM未登录")
|
||||
}
|
||||
|
||||
})
|
||||
};
|
||||
function onSDKReady(app){
|
||||
onMessageReceived();
|
||||
wx.$TUIKit.off(TIM.EVENT.ERROR,errorMsg);
|
||||
wx.$TUIKit.on(TIM.EVENT.ERROR,errorMsg,this);
|
||||
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.MESSAGE_RECEIVED,onMessageReceived);
|
||||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.MESSAGE_RECEIVED,onMessageReceived,this);
|
||||
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.KICKED_OUT,onKickOut);
|
||||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.KICKED_OUT,onKickOut,this);
|
||||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, onTotalUnreadMessageCountUpdated,this);
|
||||
};
|
||||
function errorMsg(event){
|
||||
wx.showToast({
|
||||
title:event.data.message,
|
||||
icon:'none'
|
||||
})
|
||||
};
|
||||
function onTotalUnreadMessageCountUpdated(event){
|
||||
console.log(event.data);
|
||||
};
|
||||
function onKickOut(event){
|
||||
wx.showToast({
|
||||
title: '账号在其他端登录,即将下线',
|
||||
icon:'none'
|
||||
});
|
||||
handleLogout();
|
||||
};
|
||||
function handleLogout(){
|
||||
if(wx.$TUIKit){
|
||||
wx.$TUIKit.destroy()
|
||||
};
|
||||
loginout().then(data => {
|
||||
appglobal.globalData.chatNumber=0;
|
||||
appglobal.globalData.sysNumber=0;
|
||||
appglobal.globalData.conversationList=[];
|
||||
wx.clearStorageSync();
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
function onMessageReceived(){
|
||||
getLastMsg();
|
||||
};
|
||||
function getConversationList(msg){
|
||||
wx.$TUIKit.getConversationList().then((res)=>{
|
||||
const {conversationList}=res.data;
|
||||
console.log(conversationList);
|
||||
let list=conversationList.filter(item=>item.conversationID!='C2Cadministrator');
|
||||
let unRead=0;
|
||||
list.forEach((item)=>{
|
||||
unRead=unRead+item.unreadCount;
|
||||
})
|
||||
appglobal.globalData.conversationList=list;
|
||||
appglobal.globalData.chatNumber=Number(unRead);
|
||||
setBarData(Number(unRead)+msg);
|
||||
});
|
||||
};
|
||||
function getLastMsg(){
|
||||
lastSysMsg().then(data=>{
|
||||
let msg=data.count;
|
||||
appglobal.globalData.sysNumber=msg;
|
||||
getConversationList(msg);
|
||||
}).catch(()=>{
|
||||
let msg=0;
|
||||
appglobal.globalData.sysNumber=0;
|
||||
getConversationList(msg)
|
||||
})
|
||||
};
|
||||
module.exports={
|
||||
imLogin
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
let client_type=1;
|
||||
wx.getSystemInfo({
|
||||
success (res) {
|
||||
if(res.platform=="windows" || res.platform=="mac" || res.platform=="devtools" ){
|
||||
client_type=2
|
||||
}else{
|
||||
client_type=1
|
||||
}
|
||||
},
|
||||
fail(err){
|
||||
console.log(err)
|
||||
}
|
||||
});
|
||||
module.exports = {
|
||||
client_type
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
const showModal=function(content, successCallback = function() {}, title = '提示', showCancel = false, comfirmText = '知道了', confirmColor = '#03a9f4', hasCancel = false, cancelText = '取消', cancelColor = '#000') {
|
||||
var params = {
|
||||
title: title,
|
||||
content: content,
|
||||
showCancel: showCancel,
|
||||
confirmText: comfirmText,
|
||||
confirmColor: confirmColor,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
successCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasCancel == true) {
|
||||
params.cancelText = cancelText;
|
||||
params.cancelColor = cancelColor;
|
||||
}
|
||||
wx.showModal(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装toast
|
||||
*/
|
||||
function showToast (type, text, obj) {
|
||||
let param = { duration: (obj && obj.duration) || 1500, mask: (obj && obj.isMask) || false }
|
||||
switch(type) {
|
||||
case 'text': {
|
||||
param['title'] = text || ''
|
||||
param['icon'] = 'none'
|
||||
break
|
||||
}
|
||||
case 'loading': {
|
||||
param['title'] = text || ''
|
||||
param['icon'] = 'loading'
|
||||
break
|
||||
}
|
||||
case 'success': {
|
||||
param['title'] = text || ''
|
||||
param['icon'] = 'success'
|
||||
break
|
||||
}
|
||||
case 'error': {
|
||||
param['title'] = text || ''
|
||||
param['image'] = '/images/emoji.png'
|
||||
break
|
||||
}
|
||||
default: {
|
||||
break
|
||||
}
|
||||
}
|
||||
wx.showToast(param)
|
||||
}
|
||||
|
||||
module.exports={
|
||||
showModal,
|
||||
showToast
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
|
||||
import {formatUrl} from "../utils/formatParams"
|
||||
import {getCurrentPageUrl} from "../utils/getUrl"
|
||||
import Dialog from '@vant/weapp/dialog/dialog';
|
||||
import {hostConfig} from "../utils/config"
|
||||
let isLock=false;
|
||||
let host=hostConfig().host;
|
||||
//loding 是否加loading弹窗
|
||||
function request(url, method, data, loding = false) {
|
||||
if(isLock) return;
|
||||
if (loding) {
|
||||
wx.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
let token = wx.getStorageSync('AUTH_TOKEN');
|
||||
if (!token) {
|
||||
let freelist = ["/login/wechat_mobile_login", '/login/mobile_login','/code/phone','/patient/index',"/popup","/sign/im"];//接口白名单
|
||||
let currentUrl=getCurrentPageUrl();
|
||||
if (freelist.indexOf(url) == -1 && currentUrl!="/pages/index/index") {
|
||||
let redirectUrl=formatUrl();
|
||||
// console.log("currentUrl:"+currentUrl);
|
||||
// console.log("urlreq"+url);
|
||||
// console.log('url----:'+redirectUrl);
|
||||
if(!isLock){
|
||||
isLock=true;
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login?redirectUrl='+redirectUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
let header = {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + token
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: host + url,
|
||||
method: method,
|
||||
data: data,
|
||||
header: header,
|
||||
success: function (res) {
|
||||
|
||||
var Authorization_token = res.header.Authorization;
|
||||
if (Authorization_token) {
|
||||
wx.setStorageSync('AUTH_TOKEN', Authorization_token); //当token快过期时,服务器会返回新token,本地刷新
|
||||
}
|
||||
if (loding) {
|
||||
wx.hideLoading()
|
||||
wx.stopPullDownRefresh();
|
||||
}
|
||||
let msgUrl="/patient/message/system/last";
|
||||
if (Number(res.data.code) == 200 || Number(res.data.code) == 422) {
|
||||
resolve(res.data.data);
|
||||
|
||||
}else if(Number(res.data.code) == -1){
|
||||
let list = ["/patient/order/inquiry", '/patient/order/product', '/patient/order/prescription','/patient/order/detection'];
|
||||
let index=url.lastIndexOf("/");
|
||||
let urlString=url.substring(0,index);
|
||||
if (list.indexOf(urlString) != -1 && method == "GET") {
|
||||
Dialog.confirm({
|
||||
title: '温馨提示',
|
||||
showCancelButton: false,
|
||||
confirmButtonText: "确定",
|
||||
message: '订单无法查看,点击前往首页',
|
||||
}).then(() => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/index/index',
|
||||
})
|
||||
})
|
||||
}else{
|
||||
wx.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}else if(Number(res.data.code) == 406 && msgUrl.indexOf(url)!=-1){
|
||||
reject(res.data.data)
|
||||
}else if (Number(res.data.code) == 401 || Number(res.data.code) == 403 || Number(res.data.code) == 405 || Number(res.data.code) == 406) {
|
||||
let redirectUrl=formatUrl();
|
||||
if(!isLock){
|
||||
isLock=true;
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login?redirectUrl='+redirectUrl
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
isLock=false;
|
||||
},
|
||||
// fail: function (res) {
|
||||
// wx.showToast({
|
||||
// title: '网络错误,请稍后再试',
|
||||
// icon: 'none',
|
||||
// duration: 2000
|
||||
// })
|
||||
// reject(false)
|
||||
// }
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function uploadFile(url, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.uploadFile({
|
||||
url: host + url,
|
||||
formData: data,
|
||||
success(res) {
|
||||
const result = res.data
|
||||
resolve(result)
|
||||
},
|
||||
// fail(res){
|
||||
// wx.showToast({
|
||||
// title: '网络错误,请稍后再试',
|
||||
// icon: 'none',
|
||||
// })
|
||||
// reject(false)
|
||||
// }
|
||||
})
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
request,
|
||||
uploadFile
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// router.js
|
||||
//import {getCurrentPageUrl} from "./getUrl"
|
||||
module.exports = {
|
||||
navigateTo(object) {
|
||||
let pages = getCurrentPages();
|
||||
let len = pages.length;
|
||||
let dlt = 0;
|
||||
let cur_url=object.url;
|
||||
|
||||
object.fail=function(error){
|
||||
console.log(error)
|
||||
};
|
||||
let is_otherCommon=false;
|
||||
let currentOptions=cur_url.split("?")[1];
|
||||
for (let i = 0; i < len; i++) {
|
||||
//判断是否是聊天页面
|
||||
if(pages[i].route=="TUIService/pages/index" && cur_url.indexOf("TUIService/pages/index")!=-1 ) {
|
||||
let currentOptionsArr=currentOptions.split("&");
|
||||
let cur_options=currentOptionsArr[0].toString()+"&"+currentOptionsArr[1].toString();
|
||||
let options=pages[i].options;
|
||||
//let params="currentConversationID="+options['currentConversationID']+"&order_inquiry_id="+options['order_inquiry_id']+"&inquiry_type="+options['inquiry_type']
|
||||
let params="currentConversationID="+options['currentConversationID']+"&order_inquiry_id="+options['order_inquiry_id'];
|
||||
//判断历史路由栈中是否有打开过同一个问诊聊天
|
||||
if(cur_options==params){
|
||||
dlt = i+1 ; //目标页在栈中的位置
|
||||
break;
|
||||
}else{
|
||||
is_otherCommon=true;
|
||||
dlt = i+1 ; //目标页在栈中的位置
|
||||
break;
|
||||
}
|
||||
|
||||
}else if(pages[i].route=="pages/expertDetail/expertDetail" && cur_url.indexOf("pages/expertDetail/expertDetail")!=-1){
|
||||
let options=pages[i].options;
|
||||
let params='doctor_id='+options['doctor_id'];
|
||||
if(currentOptions.indexOf(params)!=-1){
|
||||
dlt = i+1 ; //目标页在栈中的位置
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!dlt) { //这个判断里面的跳转代码可根据自己项目实际需求场景进行修改
|
||||
if (len < 10) {
|
||||
wx.navigateTo(object);
|
||||
} else {
|
||||
wx.redirectTo(object)
|
||||
}
|
||||
} else { //主要是else里面的跳转代码用来解决页面栈10层限制问题导致卡住的问题
|
||||
wx.navigateBack({
|
||||
delta: len - dlt,
|
||||
fail(error){
|
||||
console.log(error)
|
||||
},
|
||||
success(){
|
||||
// iOS使用navigateBack返回超过4级之后会导致页面点击事件失效以及都是聊天页但不是同一个用户,都对页面进行重新载入
|
||||
if(is_otherCommon || len - dlt>=5){
|
||||
wx.redirectTo(object)
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// if (getCurrentPages().length > 9) {
|
||||
// wx.redirectTo(object)
|
||||
// // this.reLaunch(object)
|
||||
// } else {
|
||||
|
||||
// wx.navigateTo(object)
|
||||
// }
|
||||
},
|
||||
goTo(object){
|
||||
//let pages=getCurrentPages();
|
||||
|
||||
},
|
||||
// 其他跳转不处理
|
||||
navigateBack(object) {
|
||||
wx.navigateBack(object)
|
||||
},
|
||||
|
||||
switchTab(object) {
|
||||
wx.switchTab(object)
|
||||
},
|
||||
|
||||
redirectTo(object) {
|
||||
wx.redirectTo(object)
|
||||
},
|
||||
|
||||
reLaunch(object) {
|
||||
wx.reLaunch(object)
|
||||
},
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// function subscribeMsg(id){
|
||||
// let id=id.toSring();
|
||||
// wx.requestSubscribeMessage({
|
||||
// tmplIds: [id],
|
||||
// success (res) {
|
||||
// console.log(res);
|
||||
// }
|
||||
// })
|
||||
// };
|
||||
// module.exports={
|
||||
// subscribeMsg
|
||||
// }
|
||||
@@ -0,0 +1,62 @@
|
||||
const dayjs = require('./dayjs.min.js');
|
||||
import { getCurrentPageUrl} from "./getUrl.js"
|
||||
const formatDate = function (value) {
|
||||
return dayjs(value).format('YYYY-MM-DD HH:mm');
|
||||
}
|
||||
const formatDateText = function (value) {
|
||||
return dayjs(value).format('YYYY年MM月DD日');
|
||||
}
|
||||
const throttle=function(fn,wait=1500){
|
||||
var flag = true;
|
||||
var timer = null;
|
||||
return function(){
|
||||
if(flag) {
|
||||
fn.apply(this,arguments);
|
||||
flag = false;
|
||||
timer = setTimeout(() => {
|
||||
flag = true
|
||||
},wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
function setBarData(total){
|
||||
let currentUrl = getCurrentPageUrl();
|
||||
if(currentUrl=='pages/index/index' || currentUrl=='pages/message/message' || currentUrl=='pages/my/my' ){
|
||||
if(total>0){
|
||||
if(total<=99){
|
||||
wx.setTabBarBadge({
|
||||
index:1,
|
||||
text: total.toString()
|
||||
})
|
||||
}else{
|
||||
wx.setTabBarBadge({
|
||||
index:1,
|
||||
text:"99+"
|
||||
})
|
||||
}
|
||||
}else{
|
||||
wx.removeTabBarBadge({
|
||||
index:1
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// function formatDate(date) {
|
||||
// var year = date.getFullYear()
|
||||
// var month = date.getMonth() + 1
|
||||
// var day = date.getDate()
|
||||
// var hour = date.getHours()
|
||||
// var minute = date.getMinutes()
|
||||
// var second = date.getSeconds()
|
||||
// return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
|
||||
// }
|
||||
module.exports = {
|
||||
formatDate,
|
||||
formatDateText,
|
||||
throttle,
|
||||
setBarData
|
||||
}
|
||||
Reference in New Issue
Block a user