You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
468 lines
12 KiB
468 lines
12 KiB
import App from './App'
|
|
|
|
// #ifndef VUE3
|
|
import Vue from 'vue'
|
|
import './uni.promisify.adaptor'
|
|
Vue.config.productionTip = false
|
|
App.mpType = 'app'
|
|
const app = new Vue({
|
|
...App
|
|
})
|
|
|
|
//设备型号判断
|
|
Vue.prototype.platform = "";
|
|
Vue.prototype.isIos = "";
|
|
Vue.prototype.isIphoneXr = false;
|
|
|
|
String.prototype.trim=function(){
|
|
return this.replace(/(^s*)|(s*$)/g, "");
|
|
}
|
|
|
|
try{
|
|
var res = uni.getSystemInfoSync(),
|
|
platform = res.platform.toLowerCase(),
|
|
system = res.system.toLowerCase(),
|
|
model = res.model.toLowerCase();
|
|
if(system.indexOf('mac') > -1 || model.indexOf('mac') > -1 || model.indexOf('iphone 12/13 mini') > -1) platform = 'ios';
|
|
if(system.indexOf('ios') > -1 || model.indexOf('ipad') > -1) platform = 'ios';
|
|
Vue.prototype.platform = platform;
|
|
Vue.prototype.isIos = platform == 'ios' ? true : false;
|
|
Vue.prototype.isIphoneXr = (platform == "ios") && (res.model.toLowerCase().indexOf("iphone x")>-1);
|
|
if(NODE_ENV == 'development') Vue.prototype.isIos = '';
|
|
if(platform.indexOf('windows') > -1) Vue.prototype.isPc = true
|
|
if(model == 'pc') Vue.prototype.isPc = true
|
|
}catch(e){
|
|
}
|
|
|
|
|
|
Vue.prototype.env_val = 'xcx';
|
|
Vue.prototype.is_pc = false;
|
|
Vue.prototype.isMobile = false;
|
|
|
|
function isMobile() {
|
|
var userAgentInfo = navigator.userAgent;
|
|
|
|
var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
|
|
|
|
var mobile_flag = false;
|
|
|
|
//根据userAgent判断是否是手机
|
|
for (var v = 0; v < mobileAgents.length; v++) {
|
|
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
|
|
mobile_flag = true;
|
|
break;
|
|
}
|
|
}
|
|
var screen_width = window.screen.width;
|
|
var screen_height = window.screen.height;
|
|
|
|
//根据屏幕分辨率判断是否是手机
|
|
if (screen_width > 325 && screen_height < 750) {
|
|
mobile_flag = true;
|
|
}
|
|
|
|
return mobile_flag;
|
|
}
|
|
|
|
|
|
function trim(str, type = 'both') {
|
|
if (type == 'both') {
|
|
//去除两端
|
|
return str.replace(/^\s+|\s+$/g, '');
|
|
} else if (type == "left") {
|
|
//去除左边
|
|
return str.replace(/^\s*/, '');
|
|
} else if (type == 'right') {
|
|
//去除右边
|
|
return str.replace(/(\s*$)/g, '');
|
|
} else if (type == 'all') {
|
|
//去除所有
|
|
return str.replace(/\s+/g, '');
|
|
} else {
|
|
return str;
|
|
}
|
|
}
|
|
|
|
function isOpenMode() {
|
|
var system = {
|
|
win: false,
|
|
mac: false,
|
|
xll: false,
|
|
ipad: false
|
|
};
|
|
var p = navigator.platform;
|
|
system.win = p.indexOf("Win") == 0;
|
|
system.mac = p.indexOf("Mac") == 0;
|
|
system.xll = (p == "X11") || (p.indexOf("Linux") == 0);
|
|
system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
|
|
if ((system.win || system.mac || system.xll || system.ipad) && !Vue.prototype.isMobile) {
|
|
var ua = navigator.userAgent.toLowerCase();
|
|
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
|
// "在PC端微信上打开的"
|
|
Vue.prototype.env_val = 'pc_weixin';
|
|
} else {
|
|
// "在PC端非微信上打开的"
|
|
Vue.prototype.env_val = 'pc';
|
|
}
|
|
Vue.prototype.isPc = true;
|
|
} else {
|
|
var ua = navigator.userAgent.toLowerCase();
|
|
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
|
// "在手机端微信上打开的"
|
|
Vue.prototype.env_val = 'phone_weixin';
|
|
} else {
|
|
// "在手机上非微信上打开的"
|
|
Vue.prototype.env_val = 'phone';
|
|
}
|
|
}
|
|
}
|
|
|
|
Vue.prototype.xcxtype = -1;
|
|
Vue.prototype.provider_baidu = "baidu";
|
|
Vue.prototype.provider_weixin = "weixin";
|
|
Vue.prototype.provider_alipay = "alipay";
|
|
Vue.prototype.provider = '';
|
|
try{
|
|
uni.getProvider({
|
|
service: 'oauth',
|
|
success: function (res) {
|
|
if (~res.provider.indexOf(Vue.prototype.provider_baidu)) {
|
|
Vue.prototype.xcxtype = 1;
|
|
Vue.prototype.provider = Vue.prototype.provider_baidu;
|
|
}
|
|
if (~res.provider.indexOf(Vue.prototype.provider_weixin)) {
|
|
Vue.prototype.xcxtype = 0;
|
|
Vue.prototype.provider = Vue.prototype.provider_weixin;
|
|
}
|
|
if (~res.provider.indexOf(Vue.prototype.provider_alipay)) {
|
|
Vue.prototype.xcxtype = 2;
|
|
Vue.prototype.provider = Vue.prototype.provider_alipay;
|
|
}
|
|
|
|
if(Vue.prototype.xcxtype == -1){
|
|
Vue.prototype.isMobile = isMobile();
|
|
isOpenMode();
|
|
}else{
|
|
Vue.prototype.isMobile = true;
|
|
}
|
|
}
|
|
});
|
|
}catch(e){
|
|
isOpenMode();
|
|
Vue.prototype.isMobile = isMobile();
|
|
}
|
|
|
|
// const NODE_ENV = 'development';
|
|
const NODE_ENV = 'production';
|
|
if(Vue.prototype.provider == Vue.prototype.provider_weixin){
|
|
if (NODE_ENV == "development") {
|
|
Vue.prototype.request_domain = 'http://jasonyizherenxin.checkcopy.com/';
|
|
} else {
|
|
Vue.prototype.request_domain = 'https://api.yizherenxin.cn/';
|
|
}
|
|
Vue.prototype.cssUrl = Vue.prototype.request_domain + '/images/frontend/user/';
|
|
}else{
|
|
if(NODE_ENV == 'development'){
|
|
Vue.prototype.request_domain = "http://jasonyizherenxin.checkcopy.com/";
|
|
}else{
|
|
Vue.prototype.request_domain = "https://api.yizherenxin.cn/";
|
|
}
|
|
Vue.prototype.cssUrl = Vue.prototype.request_domain + '/images/frontend/user/';
|
|
}
|
|
|
|
Vue.prototype.appid = '';
|
|
Vue.prototype.USER_SOURCE_WX_XCX = 1;
|
|
Vue.prototype.USER_SOURCE_WX_H5 = 2;
|
|
Vue.prototype.USER_SOURCE_PC = 3;
|
|
Vue.prototype.USER_SOURCE_H5 = 4;
|
|
if(Vue.prototype.provider == Vue.prototype.provider_weixin) {
|
|
var wxXcxAccountInfo = wx.getAccountInfoSync();
|
|
Vue.prototype.appid = wxXcxAccountInfo.miniProgram.appId;
|
|
const pagesView = getCurrentPages();
|
|
const currentPageView = pagesView[pagesView.length - 1];
|
|
Vue.prototype.View = currentPageView+'New';
|
|
}
|
|
|
|
const CODE_SUCCESS = 0;
|
|
const CODE_ERROR = 40001;
|
|
const CODE_LOGIN_EXIPRE = 40002;
|
|
|
|
Vue.prototype.user_preview = 1;
|
|
Vue.prototype.edit_preview = 2;
|
|
Vue.prototype.add_preview = 3;
|
|
Vue.prototype.edit_album = 4;
|
|
|
|
function removeLogin() {
|
|
removeToken()
|
|
removeUinfo()
|
|
}
|
|
|
|
function req(url, data={}, method = 'POST', header={}) {
|
|
var domain = Vue.prototype.request_domain;
|
|
if(Vue.prototype.appid != '') {
|
|
data.appid = Vue.prototype.appid;
|
|
data.xcx_scource = Vue.prototype.USER_SOURCE_WX_XCX;
|
|
}else{
|
|
domain = '/api/';
|
|
if(Vue.prototype.isMobile){
|
|
data.xcx_scource = Vue.prototype.USER_SOURCE_H5;
|
|
if(Vue.prototype.env_val.indexOf('weixin') > -1) data.xcx_scource = Vue.prototype.USER_SOURCE_WX_H5;
|
|
}else{
|
|
data.xcx_scource = Vue.prototype.USER_SOURCE_PC;
|
|
}
|
|
}
|
|
|
|
var getWxH5LoginConfigUri = 'common/wxh5_login'
|
|
var noNeedLoginFunc = [
|
|
getWxH5LoginConfigUri,
|
|
'client/user/login'
|
|
]
|
|
var isNeedLogin = !noNeedLoginFunc.includes(url);
|
|
|
|
var headerObj = {'content-type': 'application/x-www-form-urlencoded'};
|
|
var token = getToken();
|
|
if(token) headerObj.AUTH = token
|
|
|
|
return new Promise((resolve, reject) => {
|
|
uni.request({
|
|
method: method,
|
|
url: domain+url,
|
|
data: data,
|
|
header: headerObj,
|
|
async: false,
|
|
success(res) {
|
|
try{
|
|
var rdata = res.data;
|
|
if(rdata.code != CODE_SUCCESS) {
|
|
if(rdata.code==CODE_LOGIN_EXIPRE && data.xcx_scource == Vue.prototype.USER_SOURCE_WX_H5 && url != getWxH5LoginConfigUri && data.repeat != 1){
|
|
removeLogin();
|
|
|
|
var logindatac = new Object();
|
|
logindatac.redirect_uri = location.origin;
|
|
logindatac.state = 'user';
|
|
var checkin_depart_id = uni.getStorageSync('checkin_depart_id');
|
|
if(checkin_depart_id){
|
|
logindatac.state += '-d'+checkin_depart_id;
|
|
}
|
|
|
|
const pagesc = getCurrentPages();
|
|
const currentPagec = pagesc[pagesc.length - 1];
|
|
var pageUrlc = '/'+currentPagec.route;
|
|
uni.setStorageSync('rebackPagePath', pageUrlc);
|
|
|
|
var doctor_id = uni.getStorageSync('doctor_id');
|
|
req(getWxH5LoginConfigUri+'/?did='+doctor_id, logindatac, 'POST').then(data=>{
|
|
if(data == -1 || !data.authurl) return;
|
|
// location.href = data.authurl;
|
|
this.$nav.navToPath(data.authurl)
|
|
});
|
|
return;
|
|
}
|
|
|
|
if(data.xcx_scource == Vue.prototype.USER_SOURCE_WX_XCX && !data.repeat && rdata.code==CODE_LOGIN_EXIPRE && url != '/api/common/xcx_login'){
|
|
removeLogin();
|
|
xcx_login(url, data, method).then(data=>{
|
|
return resolve(data);
|
|
});
|
|
return;
|
|
}
|
|
|
|
uni.showModal({
|
|
title: '提示',
|
|
showCancel: false,
|
|
content: rdata.msg ? rdata.msg+'|'+rdata.code : '网络错误,请重试|'+res.statusCode,
|
|
success: function (rs) {
|
|
if (rs.confirm && rdata.code==CODE_LOGIN_EXIPRE) {
|
|
removeLogin();
|
|
const pages = getCurrentPages();
|
|
const currentPage = pages[pages.length - 1];
|
|
let pageUrl = '/'+currentPage.route;
|
|
if(data.xcx_scource == Vue.prototype.USER_SOURCE_WX_H5){
|
|
// uni.navigateTo({
|
|
// url: '/pages/index/index'
|
|
// });
|
|
this.$nav.navToPath('/pages/index/index')
|
|
}else{
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
|
|
return resolve("-1");
|
|
}else{
|
|
return resolve(res.data.data);
|
|
}
|
|
}catch(e){
|
|
console.log(e)
|
|
|
|
uni.showModal({
|
|
title: '提示',
|
|
showCancel: false,
|
|
content: '请求数据出错8|f',
|
|
success: function (rs) {
|
|
return resolve("-1");
|
|
}
|
|
});
|
|
}
|
|
},
|
|
fail(err) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
showCancel: false,
|
|
content: '网络错误,请重试|f|'+JSON.stringify(err),
|
|
success: function (rs) {
|
|
return resolve("-1");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function xcx_login(url, eqdata={}, method = 'POST') {
|
|
return new Promise((resolve, reject) => {
|
|
wx.login({
|
|
success (res) {
|
|
if (res.code) {
|
|
var pdata = new Object();
|
|
pdata.code = res.code;
|
|
var doctor_id = uni.getStorageSync('doctor_id');
|
|
pdata.state = 'user-'+doctor_id;
|
|
|
|
req('/api/common/xcx_login', pdata).then(data=>{
|
|
var udata = data
|
|
if(udata && udata.jwttoken) {
|
|
setToken(udata.jwttoken)
|
|
setUinfo(JSON.stringify(udata))
|
|
}
|
|
|
|
pdata.repeat = 1;
|
|
req(url, pdata, method).then(data=>{
|
|
return resolve(data);
|
|
});
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
function toPage(path){
|
|
if(Vue.prototype.provider == Vue.prototype.provider_weixin){
|
|
if(path.indexOf('/index/index') == -1){
|
|
wx.navigateTo({
|
|
url: path
|
|
});
|
|
}else{
|
|
wx.reLaunch({
|
|
url: path
|
|
});
|
|
}
|
|
|
|
}else{
|
|
if(path.indexOf('/index/index') == -1){
|
|
uni.navigateTo({
|
|
url:path
|
|
});
|
|
}else{
|
|
uni.reLaunch({
|
|
url:path
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
function navToPath(path, isreLaunch = false) {
|
|
// #ifdef MP-WEIXIN
|
|
if(path.indexOf('/pages/index/index') == -1 && !isreLaunch){
|
|
wx.navigateTo({
|
|
url: path
|
|
});
|
|
}else{
|
|
wx.reLaunch({
|
|
url: path
|
|
});
|
|
}
|
|
// #endif
|
|
|
|
// #ifdef H5
|
|
location.href = path;
|
|
// #endif
|
|
}
|
|
|
|
function modelShow(content, path="",title="提示") {
|
|
uni.showModal({
|
|
title: title,
|
|
showCancel: false,
|
|
content: content,
|
|
success: function (rs) {
|
|
if(rs.confirm && path != ""){
|
|
toPage(path);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function getToken() {
|
|
var did = uni.getStorageSync('doctor_id')
|
|
if(!did) return ""
|
|
return uni.getStorageSync('token_'+did)
|
|
}
|
|
|
|
function removeToken() {
|
|
var did = uni.getStorageSync('doctor_id')
|
|
if(!did) return ""
|
|
uni.removeStorageSync('token_'+did)
|
|
}
|
|
|
|
function setToken(token) {
|
|
var did = uni.getStorageSync('doctor_id')
|
|
if(!did) return ""
|
|
uni.setStorageSync('token_'+did, token)
|
|
}
|
|
|
|
function removeUinfo(){
|
|
var did = uni.getStorageSync('doctor_id')
|
|
if(!did) return ""
|
|
uni.removeStorageSync('uinfo_'+did)
|
|
}
|
|
|
|
function setUinfo(info){
|
|
var did = uni.getStorageSync('doctor_id')
|
|
if(!did) return;
|
|
uni.setStorageSync('uinfo_'+did, info)
|
|
}
|
|
|
|
|
|
//设置页main标题
|
|
function setTitlefFunc(title) {
|
|
uni.setNavigationBarTitle({
|
|
title: title || ''
|
|
});
|
|
};
|
|
|
|
Vue.prototype.$setTitle = {setTitlefFunc}
|
|
Vue.prototype.$pop = {modelShow}
|
|
Vue.prototype.$func = {toPage}
|
|
Vue.prototype.$http = {req}
|
|
Vue.prototype.$trim = {trim}
|
|
Vue.prototype.$token = {getToken}
|
|
Vue.prototype.$settoken = {setToken}
|
|
Vue.prototype.$setuinfo = {setUinfo}
|
|
Vue.prototype.$nav = { navToPath };
|
|
|
|
app.$mount()
|
|
// #endif
|
|
|
|
// #ifdef VUE3
|
|
import { createSSRApp } from 'vue'
|
|
export function createApp() {
|
|
const app = createSSRApp(App)
|
|
return {
|
|
app
|
|
}
|
|
}
|
|
// #endif
|