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.
406 lines
11 KiB
406 lines
11 KiB
2 years ago
|
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, "");
|
||
|
}
|
||
|
|
||
|
// const NODE_ENV = 'development';
|
||
|
const NODE_ENV = 'production';
|
||
|
if(NODE_ENV == 'development'){
|
||
|
Vue.prototype.cssUrl = '/static/images/frontend/';
|
||
|
Vue.prototype.request_domain = "http://xmztest.yitongtang66.com/";
|
||
|
}else{
|
||
|
Vue.prototype.cssUrl = 'https://xmz.yitongtang66.com/assets/img/new/';
|
||
|
Vue.prototype.request_domain = "https://xmz.yitongtang66.com/";
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}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();
|
||
|
}
|
||
|
|
||
|
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 = 200;
|
||
|
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() {
|
||
|
uni.removeStorageSync('token');
|
||
|
uni.removeStorageSync('uuid');
|
||
|
uni.removeStorageSync('nickname');
|
||
|
uni.removeStorageSync('avatar');
|
||
|
uni.removeStorageSync('level_id');
|
||
|
uni.removeStorageSync('level_name');
|
||
|
uni.removeStorageSync('is_admin');
|
||
|
uni.removeStorageSync('avatar_full');
|
||
|
uni.removeStorageSync('create');
|
||
|
uni.removeStorageSync('uuid_str');
|
||
|
}
|
||
|
|
||
|
function req(url, data={}, method = 'POST') {
|
||
|
var domain = Vue.prototype.request_domain;
|
||
|
data.xcxtype = 3;
|
||
|
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;
|
||
|
data.host = location.host;
|
||
|
}else{
|
||
|
data.xcx_scource = Vue.prototype.USER_SOURCE_PC;
|
||
|
data.host = location.host;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(NODE_ENV == 'development') data.env = 'dev';
|
||
|
|
||
|
var headerObj = {'content-type': 'application/x-www-form-urlencoded'};
|
||
|
var token = uni.getStorageSync('token');
|
||
|
var uuid = uni.getStorageSync('uuid');
|
||
|
|
||
|
var loginFunc = '';
|
||
|
if(data.xcx_scource == Vue.prototype.USER_SOURCE_WX_XCX) loginFunc = 'ai_xcx_login';
|
||
|
data.submit_source = data.xcx_scource;
|
||
|
data.is_ai = 1;
|
||
|
if(token && uuid && url != loginFunc){
|
||
|
data.token = token;
|
||
|
data.user_id = uuid;
|
||
|
}
|
||
|
|
||
|
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(data.xcx_scource == Vue.prototype.USER_SOURCE_WX_XCX && !data.repeat && rdata.code==CODE_LOGIN_EXIPRE && url != 'userapi/login2/weChatLogin'){
|
||
|
removeLogin();
|
||
|
xcx_login(url, data, method).then(data=>{
|
||
|
return resolve(data);
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if(data.xcx_scource == Vue.prototype.USER_SOURCE_H5 && res.data.info.indexOf('请先登录')>-1){
|
||
|
location.href="/pages/jumpxcx/jumpxcx";
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if(rdata.code==CODE_LOGIN_EXIPRE && data.xcx_scource == Vue.prototype.USER_SOURCE_WX_H5 && url != 'ai_get_mplogin_url'){
|
||
|
var logindatac = new Object();
|
||
|
logindatac.host = location.host;
|
||
|
|
||
|
const pagesc = getCurrentPages();
|
||
|
const currentPagec = pagesc[pagesc.length - 1];
|
||
|
var pageUrlc = '/'+currentPagec.route;
|
||
|
logindatac.state = encodeURIComponent(pageUrlc);
|
||
|
req('ai_get_mplogin_url', logindatac).then(data=>{
|
||
|
if(data == -1 || !data.login_link) return;
|
||
|
location.href = data.login_link;
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
uni.showModal({
|
||
|
title: '提示',
|
||
|
showCancel: false,
|
||
|
content: rdata.msg ? rdata.msg : '网络错误,请重试|'+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?url='+encodeURIComponent(pageUrl)
|
||
|
});
|
||
|
}else{
|
||
|
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return resolve("-1");
|
||
|
}else{
|
||
|
return resolve(res.data.data);
|
||
|
}
|
||
|
}catch(e){
|
||
|
uni.showModal({
|
||
|
title: '提示',
|
||
|
showCancel: false,
|
||
|
content: '请求数据出错|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;
|
||
|
req('userapi/login2/weChatLogin', pdata).then(data=>{
|
||
|
uni.setStorageSync('token', data.token);
|
||
|
uni.setStorageSync('uuid', data.userId);
|
||
|
uni.setStorageSync('uuid_str', data.userIdStr);
|
||
|
uni.setStorageSync('nickname', data.nickname);
|
||
|
uni.setStorageSync('avatar', data.avatar);
|
||
|
uni.setStorageSync('level_id', data.level_id);
|
||
|
uni.setStorageSync('level_name', data.level_name);
|
||
|
uni.setStorageSync('avatar_full', data.avatar_full);
|
||
|
uni.setStorageSync('create', data.create);
|
||
|
if(data.is_admin) uni.setStorageSync('is_admin', data.is_admin);
|
||
|
|
||
|
eqdata.repeat = 1;
|
||
|
req(url, eqdata, 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 modelShow(content, path="",title="提示") {
|
||
|
uni.showModal({
|
||
|
title: title,
|
||
|
showCancel: false,
|
||
|
content: content,
|
||
|
success: function (rs) {
|
||
|
if(rs.confirm && path != ""){
|
||
|
toPage(path);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
Vue.prototype.$pop = {modelShow}
|
||
|
Vue.prototype.$func = {toPage}
|
||
|
Vue.prototype.$http = {req}
|
||
|
Vue.prototype.$trim = {trim}
|
||
|
|
||
|
app.$mount()
|
||
|
// #endif
|
||
|
|
||
|
// #ifdef VUE3
|
||
|
import { createSSRApp } from 'vue'
|
||
|
export function createApp() {
|
||
|
const app = createSSRApp(App)
|
||
|
return {
|
||
|
app
|
||
|
}
|
||
|
}
|
||
|
// #endif
|