| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016 |
- const utils = require('./util.js');
- const h5util = require('./h5util.js');
- const api = require('./api.js');
- const app = getApp();
- // let WebIM = (wx.WebIM = require("../hxChatSDK/utils/WebIM")["default"]);
- /**
- * H5版的发布地址目录:测试环境
- * /data/nginx proxy manager/data/web/xcx_h5
- * 域名:http://xcxh5.ts.zhiqiyun.com/
- */
- /**
- * H5版的发布地址目录:148服务器
- * /data/web/module.lvluocloud.com
- * 域名:https://module.lvluocloud.com
- */
- const env = {
- NODE_ENV: 'dev',
- dev: {
- apiUrl: 'https://apitest.zhiqiyun.com',
- isSolution: false,
- shareAppid:'ZQ4KaYIMHTypO0T',
- H5_module_url:'http://xcxh5.ts.zhiqiyun.com'
- // apiUrl: 'https://apitest.tongyu99.com'
- },
- prd: {
- apiUrl: 'https://apimall.zhiqiyun.com',
- isSolution: false,
- shareAppid:'ZQCK1g7w7NKYAYP',
- H5_module_url:''
- },
- pota: {
- // apiUrl: 'http://192.168.110.59:8098' //f
- // apiUrl: 'http://192.168.110.176:8098' ,//yx
- apiUrl: 'http://192.168.110.195:8098', //xw
- // apiUrl: 'http://192.168.110.182:8098' ,//zf
- isSolution: false,
- shareAppid:'ZQ4KaYIMHTypO0T',
- H5_module_url:''
- }
- }
- var header = {
- 'content-type': 'application/x-www-form-urlencoded',
- 'appId': 'ZQ4KaYIMHTypO0T', //绿萝云测试
- // 'appId': 'ZQKmmjlYyTRmssC', //绿萝云正式
- // 'appId': 'ZQDGetYBDwHbfaP',//绿萝大药房测试
- // 'appId': 'ZQKmmjlYyTRmssC',//绿萝云正式
- // 'appId': 'ZQDGetYBDwHbfaP',//绿萝大药房测试
- // 'appId': 'ZQDAvgsQ4P51n1b',//绿萝大药房正式独立租户
- // 'appId': 'ZQjtblxKOibbZsE',//绿萝社区诊所测试
- // 'appId': 'ZQHGg8rQYqkcKvV',//绿萝中医馆测试
- // 'appId': 'ZQP48U6KeLNQZXN',//绿萝医疗美容测试
- // 'appId': 'ZQaw2Mgigmwsxwr',//绿萝专科门诊测试
- // 'appId': 'ZQrbSJm5S694cXo',//泽惠云测试
- // 'appId': 'ZQLyCKPHBHUTgpj',//泽惠云正式
- // 'appId': 'ZQYLXwCoEdE13j9',//桃燕禧测试
- // 'appId':'ZQuNAVEkY3ClG2D',//桃燕禧正式
- // 'appId':'ZQ6XiKauuAoSyfS',//金药堂
- // 'appId':'ZQ17g14A1SXrlNU',//本吉口腔
- }
- /**小程序配置 */
- const publics = {
- WX_GZH_APPID: 'wx891371f1700a6806',
- WX_GZH_URI: 'http://h5.cheese-vip.com/comm/login/login',
- 'weixinGzAppid': 'wxf3bf18d2889d98ad', //默认公众号appid
- // 'appId': 'ZQCK1g7w7NKYAYP', //正式固定的appid(绿萝云助手运营后台)
- 'appId': env[env.NODE_ENV].shareAppid, //测试绿萝云运营平台appid(系统运营租户)
- 'H5_module_url':env[env.NODE_ENV].H5_module_url, //测试绿萝云运营平台appid(系统运营租户)
- picUrls: 'https://zhiqiyun.oss-cn-hangzhou.aliyuncs.com/static/', //图片地址
- 'copyrighttitle': '智企云', //底部版权公司名称
- 'copyrighttel': '400-698-5980', //底部版权服务电话
- 'copyrightlogo': 'zhiqiyun', //底部版权 logo 文件名
- 'yaomeng': 'https://cfwz.yaomengwang.cn/hunan?enterpriseCode=hnty&orderId=', //药盟接口地址
- 'storemanagers': 'https://websmall.zhiqiyun.com?appId=', //saas门店管理地址(智企云所有)
- 'channel': '', //处方中间渠道号 SAAS系统为空
- 'is_customer_pick_up': false,
- mapLBSKEY: 'XMCBZ-7K3WN-JD3FA-SDBGN-ZYVU3-MZBQZ',
- 'iconSrc': 'blue/',
- 'titleTopBgColor': '#1a83ff',
- //小程序ID wx987a09d18df068be
- //药店版模板小程序:wxddcf0549757d4f61
- //中医馆方案模板小程序:wxccea26be900083b6
- // 'mapLBSKEY': 'B32BZ-KIP6Q-6IL57-4XOK2-EYOKV-4SBA5',//泽惠云
- // 'iconSrc': 'blue/',
- // 'titleTopBgColor': '#1a83ff',
- //小程序ID wx967c93213cd77e0d
- // 桃燕禧小程序ID
- // 'mapLBSKEY': 'KWKBZ-BVJWJ-QIGFM-DEITX-56FZ5-OGFSH',
- //wxb352884750204cd3
- // 金药堂小程序ID
- // 'mapLBSKEY': 'LWZBZ-K7WWQ-52L56-2ZCIE-F4PJO-2NBU5',
- //wxbb4bc21cf658d44d
- // 本吉口腔小程序ID
- // 'mapLBSKEY': 'GIKBZ-H6JKT-DLTXX-VO4HD-GPRFJ-7TFHI',
- //wxa1ba85dfdafad298
- }
- function getHeader(content_type, appID) {
- var appId = '';
- if (appID) {
- appId = appID;
- } else {
- appId = getStorage('appId');
- if (!appId) {
- appId = header.appId;
- setStorage('appId', appId)
- }
- }
- var headers = {
- "content-type": content_type ? content_type : 'application/x-www-form-urlencoded',
- "appId": appId,
- };
- return headers;
- }
- /*
- * 获取token
- */
- const getToken = (success, appId, isKDX) => {
- var token = '';
- if (isKDX) {
- token = getStorage('S_AUTH_TOKEN');
- } else {
- token = getStorage('AUTH_TOKEN');
- }
- // let token = 'JKoXWFCY1yB93BQdLVb9BcibWAaexceyR';
- if (token) {
- success.call(this, token);
- return false;
- } else {
- loadToken(data => {
- success.call(this, data);
- }, appId, isKDX);
- }
- }
- const loadToken = (success, appId, isKDX) => {
- let that = this
- uni.request({
- url: env[env.NODE_ENV].apiUrl + '/api/access_token',
- data: {},
- method: 'get',
- header: getHeader('', appId),
- success(json) {
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code !== 0) return msg(json.data.msg)
- if (isKDX) {
- setStorage('S_AUTH_TOKEN', json.data.data);
- } else {
- setStorage('AUTH_TOKEN', json.data.data);
- }
- success.call(that, json.data.data);
- },
- fail() {
- msg('access_token 获取失败');
- }
- })
- }
- /**
- * 微信小程序静默授权登录
- * @param {*} parentId
- * @param {*} merchantId
- * @param {*} type 用户来源类型 1 小程序搜索 2 活动报名 3 名片分享 4商品分享 5店铺分享 6文章分享 7小程序分享 8素材分享 9公众号分享 10公众号搜索 11企微活码 12微信活码 13手工录入 14 5G消息进入
- */
- const silenceLogin = (parentId, merchantId, type) => {
- return new Promise(async(resolve, reject) => {
- let logins =await isAuthFn(false)
- if (!logins) { //未登录
- // #ifdef MP-WEIXIN || MP-TOUTIAO
- uni.login({
- success(res) {
- console.log('静默授权登录>>>', res);
- let params = {
- code: res.code,
- parentId: parentId ? parentId : '',
- merchantId: merchantId ? merchantId : ''
- }
- var url = '';
- // #ifdef MP-WEIXIN
- url = '/api/v3/silence/login';
- // #endif
- // #ifdef MP-TOUTIAO
- url = '/api/v3/tiktok/login';
- // #endif
- postRequest(url, params, data => {
- if (data.token) setStorage('AUTH_TOKEN', data.token);
- setStorage('userInfo', data);
- savePortAndSource({
- uid: getStorage('userInfo').id,
- source: type
- })
- // getRequest('/api/config',{},data=>{
- // if(data.is_not_open_im != 1) getIMToken(false);
- // })
- resolve()
- });
- }
- });
- // #endif
- // #ifdef H5
- //判断是否为微信内环境,只有内环境才执行静默授权登录
- // env.NODE_ENV=='prd' 只有正式环境域名可静默授权,如果是测试环境仍用手机号登陆
- if (utils.isWeixin() && env.NODE_ENV=='prd') {
- console.log('$$$$$$$$微信环境,进入静默授权')
- getApp().wxOauth(parentId, merchantId, 'snsapi_base');
- resolve()
- }else{
- resolve()
- }
- // #endif
- } else {
- // getRequest('/api/config',{},data=>{
- // if(data.is_not_open_im != 1) getIMToken(false);
- // })
- // initIMChat();
- savePortAndSource({
- uid: getStorage('userInfo').id,
- source: type
- })
- resolve()
- }
- })
- }
- const onNetworkStatusChangeIM = () => {
- // console.log('IM>>>>>>>>>>>>>网络变化调用');
- // uni.onNetworkStatusChange(info => {
- // msg('切换了网络,开始重连');
- // WebIM.conn.close();
- // setTimeout(() => {
- // initIMChat();
- // }, 500);
- // });
- }
- /**
- * 初始化 IMsdk
- */
- const initIMChat = () => {
- var user = getStorage('userInfo');
- let myUsername = uni.getStorageSync("myUsername")
- var imToken = getStorage('imToken');
- console.log(imToken)
- if (imToken) {
- if (myUsername) {
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: myUsername,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- } else {
- getRequest('/api/v3/im/em/userId', {
- userId: user.id
- }, suc => {
- uni.setStorage({
- key: "myUsername",
- data: 'RS_' + suc
- });
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: 'RS_' + suc,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- });
- }
- } else {
- getRequest('/api/v3/im/em/userToken', {}, suc => {
- setStorage('imToken', suc.token);
- uni.setStorage({
- key: "myUsername",
- data: 'RS_' + suc.id
- });
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: suc.id,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- });
- }
- }
- const getIMToken = (isUpdatToken) => {
- var user = getStorage('userInfo');
- getRequest('/api/v3/im/em/userToken', {}, suc => {
- setStorage('imToken', suc.token);
- uni.setStorage({
- key: "myUsername",
- data: 'RS_' + suc.id
- });
- if (isUpdatToken) {
- //更新token
- getApp().globalData.conn.open({
- user: 'RS_' + suc.id,
- accessToken: getStorage('imToken'),
- });
- getApp().globalData.onLoginSuccess(uni.getStorageSync("myUsername"));
- } else {
- // initIMChat();
- }
- }, true);
- }
- /**
- * 跳转进入消息列表
- */
- const jumpConversation = () => {
- if (!isLogins(true)) { //未登录
- return;
- }
- getIMToken(true);
- }
- /**
- * 跳入聊天
- * @param {Object} userId 对方用户ID
- * @param {Object} avatar 对方用户头像
- * @param {Object} realName 对方用户名称
- */
- const jumpSingleChatRoom = function(userId, avatar, realName) {
- getRequest('/manage/v3/im/em/userId', {
- id: userId
- }, suc => {
- var my = uni.getStorageSync("myUsername");
- var nameList = {
- myName: my,
- your: 'rs_' + suc
- };
- uni.setStorage({
- key: 'imUserInfo_' + nameList.your,
- data: {
- avatar: avatar,
- id: userId,
- nickName: realName
- }
- });
- uni.navigateTo({
- url: "/chat/chatroom/chatroom?username=" + JSON.stringify(nameList)
- });
- });
- }
- const getWXUserProfile = (suc) => {
- let that = this;
- var sessionKey = '';
- var openid = '';
- getApp().globalData.getCheckSessoin(json => {
- sessionKey = json.session_key;
- openid = json.openid;
- });
- try {
- uni.getUserProfile({
- desc: '完善信息',
- success: res => {
- updataWxInfos(res.iv, res.encryptedData, sessionKey, openid, suc);
- },
- fail: res => {
- console.log('授权失败数据>>>', res);
- msg(res);
- }
- });
- } catch (e) {
- // 老版
- wx.getUserInfo({
- success: function(ress) {
- updataWxInfos(res.iv, res.encryptedData, sessionKey, openid, suc);
- }
- });
- }
- }
- /**
- * 保存微信头像
- */
- const updataWxInfos = (iv, encryptedData, sessionKey, openid, suc) => {
- if (!encryptedData || !iv) return false;
- let _params = {
- sessionKey: sessionKey,
- openId: openid,
- iv: iv,
- encryptedData: encryptedData
- };
- postRequest('/api/user/weixin/update', _params, json => {
- setStorage('userInfo', json);
- suc.call();
- });
- }
- const clearValueEmpty = (data) => {
- let keyValue = {};
- for (let key in data) {
- let value = typeof data[key];
- if (value == 'string' && value) {
- if (data[key] != 'undefined' && data[key] != " " && data[key] != undefined && data[key] !=
- null) {
- keyValue[key] = data[key];
- }
- // keyValue[key] = data[key];
- } else if (value == 'number' && value != null) {
- keyValue[key] = data[key];
- } else if (value == 'boolean') {
- keyValue[key] = data[key];
- } else {
- if (data[key]) keyValue[key] = data[key];
- }
- }
- return keyValue;
- }
- /**
- * 公共请求
- *
- * @param {*} url 请求url
- * @param {*} data 请求参数
- * @param {*} method 请求方法
- * @param {*} success 成功函数
- * @param {*} isLoad 是否显示加载提示
- */
- const baseRequest = (url, data, method, success, isLoad) => {
- getToken(token => {
- if (isLoad) {
- loadIng('加载中');
- }
- let headers = '';
- if (url.indexOf('/v3') != -1) {
- headers = getHeader('application/json;charset=UTF-8', '');
- } else {
- headers = getHeader('application/x-www-form-urlencoded', '');
- }
- headers.authorityToken = token;
- uni.request({
- url: env[env.NODE_ENV].apiUrl + url,
- data: clearValueEmpty(data),
- method: method,
- header: headers,
- success(json) {
- if (isLoad) {
- uni.hideLoading();
- }
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code === 10021 || json.data.code === 10020) {
- // console.log("第二次执行")
- if(url=='/api/isAuth'){
- success.call(this, json.data.data);
- return false
- }else{
- removeStorage('AUTH_TOKEN');
- return redirectIndex();
- }
- }
- if (json.data.code !== 0) {
- return msg(json.data.msg)
- }
- // console.log("第二次执行")
- let data = json.data.data;
- if (typeof data === 'string' && data.indexOf("{") === 0) {
- data = JSON.parse(data);
- }
- success.call(this, data);
- },
- fail() {
- if (isLoad) {
- uni.hideLoading();
- }
- },
- // complete(){
- // success.call(this, data);
- // },
- })
- })
- }
- const loadIng = (msg) => {
- uni.showLoading({
- title: msg,
- mask: true
- })
- }
- /**POST请求 */
- const postRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/x-www-form-urlencoded'
- baseRequest(url, data, 'post', success, isLoad);
- }
- const postRequestLoding = (url, data, success, isLoding) => {
- header['content-type'] = 'application/x-www-form-urlencoded'
- baseRequest(url, data, 'post', success, false, isLoding);
- }
- /**GET请求 */
- const getRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/x-www-form-urlencoded'
- baseRequest(url, data, 'get', success, isLoad);
- }
- /**Put请求 */
- const putRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/x-www-form-urlencoded'
- baseRequest(url, data, 'put', success, isLoad)
- }
- const putRequestJson = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'put', success, isLoad)
- }
- /**public请求 */
- const getRequestKDX = (url, data, success, isLoad) => {
- baseRequestKDX(url, data, 'get', success, isLoad, publics.appId);
- }
- /**KDXPOST请求 */
- const postRequestKDX = (url, data, success, isLoad) => {
- baseRequestKDX(url, data, 'post', success, isLoad, publics.appId);
- }
- /**
- * 公共请求
- *
- * @param {*} url 请求url
- * @param {*} data 请求参数
- * @param {*} method 请求方法
- * @param {*} success 成功函数
- * @param {*} isLoad 是否显示加载提示
- */
- const baseRequestKDX = (url, data, method, success, isLoad, appId) => {
- getToken(token => {
- if (isLoad) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- }
- var headerKDX = {};
- headerKDX.authorityToken = token;
- headerKDX.appId = appId;
- if (url.indexOf('/v3') != -1) {
- headerKDX['content-type'] = 'application/json;charset=UTF-8'
- } else {
- headerKDX['content-type'] = 'application/x-www-form-urlencoded'
- }
- console.log('headerKDX==', headerKDX)
- uni.request({
- url: env[env.NODE_ENV].apiUrl + url,
- data: clearValueEmpty(data),
- method: method,
- header: headerKDX,
- success(json) {
- if (!isLoad) uni.hideNavigationBarLoading();
- uni.hideLoading();
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code === 10021 || json.data.code === 10020) {
- if (toLogin) {
- toLogin = false;
- console.log("执行登录")
- return redirectIndex();
- } else {
- console.log("不执行登录")
- return;
- }
- }
- toLogin = true;
- if (json.data.code !== 0) {
- return msg(json.data.msg)
- }
- let data = json.data.data;
- if (typeof data === 'string' && data.indexOf("{") === 0) {
- data = JSON.parse(data);
- }
- success.call(this, data);
- },
- fail() {
- if (!isLoad) uni.hideNavigationBarLoading();
- uni.hideLoading();
- }
- })
- }, appId, true)
- }
- /**
- * 上传文件
- * @param {*} url 请求url
- * @param {*} data 携带数据
- * @param {*} success 请求成功函数
- */
- const uploadFile = (url, data, success) => {
- // console.log(env[env.NODE_ENV].apiUrl + url, data)
- getToken(token => {
- uni.uploadFile({
- url: env[env.NODE_ENV].apiUrl + url,
- filePath: data,
- name: 'file',
- header: {
- 'appId': getStorage('appId') ? getStorage('appId') : header['appId'],
- 'authorityToken': token
- },
- success(res) {
- if (res.statusCode !== 200) return msg('文件上传失败');
- let data = JSON.parse(res.data);
- if (data.code !== 0) return msg(data.msg);
- success.call(this, data.data);
- },
- })
- })
- }
- /**弹窗 */
- const msg = (title, success) => {
- if (title) {
- uni.showToast({
- title: title,
- icon: 'none',
- success() {
- if (success) success.call(this);
- }
- });
- }
- return false;
- }
- const msgConfirm = (msg, success, cancel) => {
- uni.showModal({
- title: '提示',
- content: msg,
- success(res) {
- if (res.confirm) {
- success.call(this);
- } else {
- if (cancel) cancel.call(this);
- }
- }
- })
- }
- const msgConfirmText = (msg, confirmText, success, cancel) => {
- uni.showModal({
- title: '提示',
- content: msg,
- confirmText: confirmText,
- success(res) {
- if (res.confirm) {
- success.call(this);
- } else {
- if (cancel) cancel.call(this);
- }
- }
- })
- }
- const alertMsg = (msg, success) => {
- uni.showModal({
- title: '提示',
- content: msg,
- showCancel: false,
- success(res) {
- if (success) success.call(this);
- }
- })
- return false;
- }
- const load = msg => {
- uni.showLoading({
- title: msg,
- mask: true
- })
- }
- const g = (url, success, isLoad) => {
- getRequest(url, {}, success, isLoad)
- }
- const p = (url, success, isLoad) => {
- postRequest(url, {}, success, isLoad)
- }
- const send = (url, mobile, success, error) => {
- if (!mobile) {
- return msg('手机号码不能为空', error);
- }
- postRequest(url, {
- phone: mobile
- }, json => {
- if (json.code !== 0) {
- return msg(json.msg, error);
- }
- let time = 60;
- const initTime = setInterval(() => {
- time--;
- if (time > 0) {
- success.call(this, time + '秒后获取');
- } else {
- clearInterval(initTime);
- success.call(this, '获取验证码');
- }
- }, 1000)
- })
- }
- // 登陆拦截
- const redirectIndex = (params) => {
- // uni.clearStorageSync();
- removeStorage('userInfo');
- // console.log(params)
- var pages = getCurrentPages();
- // console.log("pages》》》》》登陆拦截", pages);
- let currentUrl;
- if (pages) {
- var currentPage = pages[pages.length - 1];
- if (currentPage) {
- currentUrl = currentPage.route;
- // let query = currentPage.data.query;
- // if (query) {
- // for (let key in query) {
- // const fo = key + '=' + query[key];
- // currentUrl += currentUrl.indexOf('?') > -1 ? '&' + fo : '?' + fo;
- // }
- // }
- if (currentUrl) {
- console.log('currentUrl》》》》》', currentUrl);
- setStorage("REDIRECT_URL", '/' + currentUrl);
- // #ifndef MP-WEIXIN
- if (currentUrl == 'pages/applogin/index') {
- console.log('当前已经处于登录页面,不在向下执行跳转');
- return
- }
- // #endif
- // #ifdef MP-WEIXIN
- if (currentUrl == 'pages/authorize/authorize') {
- console.log('当前已经处于登录页面,不在向下执行跳转');
- return
- }
- // #endif
- }
- }
- }
- var redirectUrl = '';
- //小程序环境设置
- var ua = window.navigator.userAgent.toLowerCase();
- //判断是否是微信环境
- if (ua.match(/MicroMessenger/i) == 'micromessenger') {
- jWeixin.miniProgram.getEnv((res) => {
- if(res.miniprogram){
- redirectUrl = '/pages/authorize/authorize' + (params ? params : '');
- }else{
- redirectUrl = '/pages/applogin/index' + (params ? params : '');
- }
- })
- }else{
- redirectUrl = '/pages/applogin/index' + (params ? params : '');
- }
- var jump = getStorage('authorize_jump') //以下解决多次跳转登录页的重点
- if (!jump || currentUrl !== 'pages/authorize/authorize') {
- //以下做token失效的操作
- setTimeout(() => {
- // uni.navigateTo({
- // url: redirectUrl
- // })
- h5util.jumpUrlExternal({
- url:redirectUrl,
- onlyWeb:false
- })
- }, 100)
- setStorage('authorize_jump', 'true')
- }
- return false;
- }
- const saveImage = (url) => {
- uni.saveImageToPhotosAlbum({
- filePath: url,
- success() {
- msg('图片保存成功');
- }
- })
- }
- const saveImageToPhotosAlbum = (url) => {
- if (!url) return msg('小程序码不存在');
- uni.getImageInfo({
- src: url,
- success(json) {
- uni.getSetting({
- success(res) {
- if (!res.authSetting['scope.writePhotosAlbum']) {
- uni.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- saveImage(json.path);
- }
- })
- } else {
- saveImage(json.path);
- }
- }
- })
- }
- })
- }
- const getConfig = (config, id) => {
- let con = {};
- config.info.forEach(inf => {
- // console.log(inf.version, inf.version ? inf.version.indexOf(id) : '-')
- if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
- con[inf.setName] = inf.setDefault;
- });
- config.card.forEach(inf => {
- if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
- con[inf.setName] = inf.setDefault;
- });
- config.realTime.forEach(inf => {
- if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
- con[inf.setName] = inf.setDefault;
- });
- return con;
- }
- const isLogin = async (error) => {
- let userInfo = getStorage('userInfo');
- if (!userInfo || !userInfo.id) {
- if (error) return false;
- // console.log("第一次执行")
- return redirectIndex();
- }
- return true;
- }
- //检测是否登录
- const isLogins = async(isGoLogin) => {
- let userInfo = getStorage('userInfo');
- if (!userInfo) {
- if (isGoLogin) {
- redirectIndex();
- }
- return false;
- }
- return true;
- }
- //检测是否登录接口形式
- const isAuthFn = (isGoLogin)=>{
- return new Promise((r,j)=>{
- postRequest('/api/isAuth',{},res=>{
- if(!res){
- if (isGoLogin) {
- redirectIndex();
- }
- }
- r(res?true:false)
- })
- })
- }
- const setStorage = (key, value) => {
- uni.setStorageSync(env.NODE_ENV + "_" + key, value)
- }
- const getStorage = (key) => {
- return uni.getStorageSync(env.NODE_ENV + "_" + key)
- }
- const removeStorage = (key) => {
- return uni.removeStorageSync(env.NODE_ENV + "_" + key);
- }
- /**
- * 缓存模板id
- */
- // const gettmplIds = () => {
- // getRequest('/api/wxmes/querylist', {}, res => {
- // setStorage('tmplIds', res)
- // console.log(res)
- // })
- // }
- //微信支付订单公共方法
- const payOrder = (id, success, type) => {
- var loctionAddressMap = getStorage('loctionAddressMap');
- var datas = {
- id: id
- };
- // #ifdef H5
- datas.payChannel = 'wx_mweb';
- // #endif
- if (loctionAddressMap) {
- datas.province = loctionAddressMap.province;
- datas.city = loctionAddressMap.city;
- };
- if (getStorage('isVideoScene')) {
- uni.checkBeforeAddOrder({
- success(res) {
- console.log('下单前置检查', res)
- datas.sceneCheckStr = JSON.stringify(res.data);
- wexinPay(datas, success, type)
- },
- })
- } else {
- wexinPay(datas, success, type)
- }
- }
- //支付中或已支付
- const payStatus = (json, id, success) => {
- if (json && json.code === 115) {
- setTimeout(res => {
- uni.hideLoading();
- isShowLoading = false;
- uni.showModal({
- title: '提示',
- content: '当前订单正在支付或30秒后重试',
- confirmText: '我知道了',
- showCancel: false,
- success(res) {}
- })
- }, 3000)
- return false;
- }
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- }
- // 支付成功回调
- const paySuccess = (id, success) => {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 1000);
- }
- // 支付失败回调
- const payFail = (id, type) => {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- if (type == 'payment') return false;
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- }
- //微信支付订单公共方法 ==活动
- const payOrders = (id, success, type) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- postRequest('/api/order/weixin/pay', {
- id: id
- }, json => {
- // console.log(json)
- payStatus(json, id, success)
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- paySuccess(id, success)
- },
- fail: function(res) {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- if (type == 'registered') {
- uni.redirectTo({
- url: '/onlineregistration/detail/detail?id=' + id,
- })
- } else {
- uni.redirectTo({
- url: '/match/activitys/activity',
- })
- }
- })
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- }
- const wexinPay = (datas, success, type) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- // #ifdef MP-WEIXIN
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log('json',json)
- payStatus(json, datas.id, success, type)
- if (getStorage('isVideoScene')) {
- console.log('拉起收银台')
- wx.requestOrderPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- orderInfo: json.orderInfo,
- paySign: json.sign,
- success: function() {
- paySuccess(datas.id, success)
- },
- fail: function(res) {
- console.log(res);
- payFail(datas.id, type)
- }
- })
- } else {
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- paySuccess(datas.id, success)
- },
- fail: function(res) {
- console.log(res);
- payFail(datas.id, type)
- }
- })
- }
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- // #ifdef MP-ALIPAY
- datas.payChannel = 'alipay_lite ';
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: json.packages,
- success: function() {
- paySuccess(datas.id, success)
- },
- fail: function(res) {
- payFail(datas.id)
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- // #ifdef H5
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- paySuccess(datas.id, success);
- // success.call(this);
- return false;
- }
- if (json.channel === 9 || json.channel === 2) {
- //调用后台判断订单是否支付成功
- window.location.href = json.payUrl;
- return false;
- }
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- }
- //微信支付订单公共方法
- const payOrdersss = (id, success) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- var loctionAddressMap = getStorage('loctionAddressMap');
- var datas = {
- id: id
- };
- if (loctionAddressMap) {
- datas.province = loctionAddressMap.province;
- datas.city = loctionAddressMap.city;
- };
- // #ifdef MP-WEIXIN
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 500);
- },
- fail: function(res) {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- // #ifdef MP-ALIPAY
- datas.payChannel = 'alipay_lite ';
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: json.packages,
- success: function() {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 500);
- },
- fail: function(res) {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- }
- /**
- * type 4为余额充值
- */
- const payAppOrder = (id, openId, type, success) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- isShowLoading = true;
- }
- var loctionAddressMap = getStorage('loctionAddressMap');
- var datas = {
- id: id,
- openId: openId
- };
- if (loctionAddressMap) {
- datas.province = loctionAddressMap.province;
- datas.city = loctionAddressMap.city;
- };
- var url = '';
- if (type == 4) {
- url = '/api/members/v2/weixin/pay';
- datas.status = type;
- } else {
- url = '/api/order/v2/weixin/pay';
- }
- postRequest(url, datas, json => {
- var urlapi = '';
- var dataP = {};
- if (type == 4) {
- urlapi = '/api/rrLogs/check'
- dataP.logsId = id;
- } else {
- urlapi = '/api/order/v2/check'
- dataP.id = id;
- }
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest(urlapi, dataP, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- return false;
- }
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- let i = 0;
- loadIng('加载中');
- let timer = setInterval(() => {
- postRequest(urlapi, dataP, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- uni.hideLoading();
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- })
- }, 500);
- },
- fail: function(res) {
- success.call(this, false);
- msg('支付失败')
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- });
- }
- const receipt = (id, success) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- postRequest('/api/receipt/weixin/pay', {
- id: id
- }, json => {
- // console.log(json)
- if (json.type === 2) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/receipt/check', {
- receiptId: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/receipt/check', {
- receiptId: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 500);
- },
- fail: function(res) {
- console.log('支付失败')
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- }
- const authSetting = (authority, success, error) => {
- // console.log(authority,success)
- // #ifndef H5
- uni.getSetting({
- success(res) {
- if (res.authSetting[authority]) {
- success.call(this);
- return false;
- }
- uni.authorize({
- scope: authority,
- success() {
- success.call(this);
- },
- fail: function(res) {
- error.call(this);
- }
- })
- }
- })
- // #endif
- }
- const getLocation = (suss) => {
- // #ifdef MP-WEIXIN
- authSetting('scope.userLocation', () => {
- // load('定位中…');
- uni.getLocation({
- type: 'gcj02',
- // isHighAccuracy: true,
- success: function(res) {
- // uni.hideLoading();
- console.log(res, "789")
- suss.call(this, res);
- },
- fail: function(res) {
- console.log("调用失败", res)
- suss.call(this, 2)
- // uni.hideLoading();
- }
- })
- }, () => {
- // uni.hideLoading();
- console.log("取消")
- suss.call(this, 1)
- });
- // #endif
- // #ifdef MP-ALIPAY
- uni.getLocation({
- type: 'gcj02',
- // isHighAccuracy: true,
- success: function(res) {
- // uni.hideLoading();
- console.log(res, "789")
- suss.call(this, res);
- },
- fail: function(res) {
- console.log("调用失败", res)
- suss.call(this, 2)
- // uni.hideLoading();
- }
- })
- // #endif
- // #ifdef H5
- uni.getLocation({
- type: 'gcj02',
- isHighAccuracy: true,
- success: function(res) {
- // uni.hideLoading();
- console.log(res)
- suss.call(this, res, "789");
- },
- fail: function(res) {
- console.log("调用失败", res)
- suss.call(this, 2)
- // uni.hideLoading();
- }
- })
- // #endif
- }
- const scopeAddress = (success) => {
- // #ifdef MP-WEIXIN
- authSetting('scope.address', () => {
- uni.chooseAddress({
- success: function(res) {
- success.call(this, res);
- },
- })
- }, () => {
- msg('未设置开放权限')
- });
- // #endif
- // #ifdef MP-ALIPAY
- uni.chooseAddress({
- success: function(res) {
- success.call(this, res);
- },
- })
- // #endif
- }
- const isAuth = () => {
- const user = getStorage('userInfo');
- return user && user.id;
- }
- // 去掉字符串中的特殊字符和转义字符
- const excludeSpecial = (s) => {
- // 去掉转义字符
- // s = s.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
- const pattern = /[`~!@#$^&*()=|{}':;',\\\[\]\.<>\/?~!@#¥……&*()——|{}【】';:""' + - - _ % 。,、?\s]/g;
- if (s != undefined || s != null) {
- s = s.replace(pattern, "")
- }
- return s;
- }
- // 行为操作
- const saveBehavior = (params, success) => {
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知
- //上级浏览ID:parentId
- //来源用户:pid
- postRequest('/api/v3/save', params, data => {
- success.call(this, data)
- })
- }
- const getBehavior = (params, success) => {
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知
- getRequest('/api/v3/get', params, data => {
- success.call(this, data)
- })
- }
- const getBehaviorCount = (params, success) => {
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知
- getRequest('/api/v3/behavior/count', params, data => {
- success.call(this, data)
- })
- }
- const getBehaviorUpdate = (params, success) => {
- //主键id:save接口返回的id
- postRequest('/api/v3/update', params, data => {
- success.call(this, data)
- })
- }
- const isTabPage = (pageName, solution_name) => {
- console.log('isTabPage', pageName)
- // pageName 当前页面channel solution_name 线上配置name
- let pass = false;
- if (pageName) {
- for (let i = 0; i < tab.length; i++) {
- let it = tab[i];
- if (solution_name && solution_name != ' ') {
- if (it.name == solution_name) {
- let tlist = it.list.map(iit => {
- return iit.channel
- })
- if (tlist.indexOf(pageName) != -1) return true
- }
- } else {
- if (it.name == 'default') {
- let tlist = it.list.map(iit => {
- return iit.channel
- })
- if (tlist.indexOf(pageName) != -1) return true
- }
- }
- }
- }
- return pass
- }
- const toTabBar = (pageName, options = {}) => {
- console.log('toTabBar', pageName)
- // let url = '/pages/tabBar/index?pageChannel='+pageName
- // if(Object.keys(options).length>0){
- // for (let i in options) {
- // url = url+'&'+i+'='+options[i]
- // }
- // }
- options.pageChannel = pageName
- console.log('toTabBar options', options)
- setStorage('optionsPageDate', options)
- uni.switchTab({
- url: '/pages/tabBar/index'
- })
- }
- /**
- * 记录用户端口和来源
- * @param port 用户端口(不需要传) 1.小程序(默认) 2.微信好友 3.微信群 4.企微好友 5.企微群 6.H5 7.公众号 8.导入 9.APP
- * @param source 来源 1 小程序搜索 2 活动报名 3 名片分享 4商品分享 5店铺分享 6文章分享 7小程序分享 8素材分享 9公众号分享 10公众号搜索 11企微活码 12微信活码 13手工录入 14 5g消息
- * @param uid 用户id
- */
- const savePortAndSource = ({
- port = 1,
- source = '',
- uid = ''
- } = {}) => {
- // 获取用户端口
- portObj = getUserPort()
- let dataP = {
- portType: portObj.port,
- resourceType: source,
- uid: uid
- };
- // 如果是从好友或群聊端口进入且没有来源则算作 通过小程序分享进入
- if ((dataP.portType == 2 || dataP.portType == 3 || dataP.portType == 4 || dataP.portType == 5) && !
- source) {
- dataP.resourceType = 7
- }
- // 端口有来源则展示端口来源
- if (portObj.resourceType) {
- dataP.resourceType = portObj.resourceType
- }
- // 默认为主动进入小程序用户,H5 APP暂时未开放,如需统计主动进入或分享H5 APP等数据需要再讨论用户来源类型
- if (!dataP.resourceType) dataP.resourceType = 1
- console.log('调用用户端口和来源保存接口:', dataP)
- postRequest('/api/v3/application/behavior/saveUserResourcePort', dataP, data => {
- });
- }
- const getWebchatAppId = () => {
- // #ifdef H5
- if (utils.isWeixin()) {
- getRequest(api.webchat_appId, {}, data => {
- if (data) {
- setStorage('webchatAppId', data);
- }
- });
- }
- // #endif
- }
- const getwxConfig = (suc) => {
- getRequest('/api/config', {}, data => {
- setStorage('configRes', JSON.stringify(data));
- getApp().globalData.upColor(true)
- suc.call(this, data);
- });
- }
- // 获取用户端口
- const getUserPort = () => {
- const sinfo = uni.getSystemInfoSync();
- let port = 1
- let resourceType = null
- // #ifdef H5
- console.log("当前端口: H5端")
- port = 6
- // #endif
- // #ifdef APP
- console.log("当前端口: APP端")
- port = 9
- // #endif
- // #ifdef MP-WEIXIN
- console.log("当前端口: 小程序端")
- port = 1
- let params = uni.getEnterOptionsSync()
- console.log("小程序端参数: ", params)
- switch (params.scene) {
- case 1007: { //单人聊天会话中的小程序消息卡片
- port = 2
- if (sinfo.environment == 'wxwork') {
- port = 4
- }
- }
- break;
- case 1008: { //群聊会话中的小程序消息卡片
- port = 3
- console.log("小程序群场景值1008")
- if (sinfo.environment == 'wxwork') {
- console.log("小程序群场景值1008 企微环境")
- port = 5
- }
- try {
- uni.getGroupEnterInfo({
- success: (res) => {
- console.log("getGroupEnterInfo 小程序群聊id:", res)
- // if (res.encryptedData && res.iv) {
- // app.globalData.getCheckSessoin(json => {
- // let _params = {
- // sessionKey: json.sessionKey,
- // openId: json.openid,
- // iv: res.iv,
- // encryptedData: res.encryptedData
- // };
- // postRequest('', _params, json => {
- // });
- // });
- // }
- },
- fail: (error) => {
- console.log("小程序群聊id error:", error)
- },
- })
- } catch (e) {
- //TODO handle the exception
- }
- }
- break;
- case 1044: { //带 shareTicket 的小程序消息卡片(群聊)
- port = 3
- if (sinfo.environment == 'wxwork') {
- port = 5
- }
- console.log("小程序群聊id:", params.shareTicket)
- try {
- uni.getGroupEnterInfo({
- success: (res) => {
- console.log("小程序群聊id:", res)
- }
- })
- } catch (e) {
- //TODO handle the exception
- }
- }
- break;
- case 1020: { //公众号 profile 页相关小程序列表(已废弃)
- port = 7
- }
- break;
- case 1035: { //公众号自定义菜单
- port = 7
- }
- break;
- case 1043: { //公众号模板消息
- port = 7
- }
- break;
- case 1074: { //公众号会话下发的小程序消息卡片
- port = 7
- }
- break;
- case 1082: { //公众号会话下发的文字链
- port = 7
- }
- break;
- case 1091: { //公众号文章商品卡片
- port = 7
- }
- break;
- case 1065: { //URL scheme 用户5g消息进入小程序
- port = 1
- resourceType = 14
- }
- break;
- default:
- break;
- }
- // #endif
- // 目前判断从企微环境打开的都算企微好友,无发获取到是从群聊还是好友聊天中打开的程序
- if (sinfo.environment == 'wxwork') {
- port = 4
- }
- console.log("进入端口类型: ", port)
- return {
- port: port,
- resourceType: resourceType
- }
- }
- /**
- * text:展示导航名
- * iconPath:未点击显示图标
- * selectedIconPath:选中图标
- * pagePath:页面路径
- * channel:匹配名
- * click:点击事件
- * index:排序
- * show:是否显示
- */
- let config = getStorage('configRes') ? JSON.parse(getStorage('configRes')) : {};
- var tab = [{
- name: 'default',
- list: [{
- text: "首页",
- iconPath: "/static/pages/images/home.png",
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'home_h.png',
- pagePath: 'pages/index/index',
- channel: 'home',
- click: 'goHome',
- index: 1,
- show: true
- },
- {
- text: "服务项目",
- iconPath: '/static/pages/images/service.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'service_h.png',
- pagePath: 'pages/service/index',
- click: 'goService',
- channel: 'service',
- index: 2,
- show: true
- },
- {
- text: "我的",
- iconPath: '/static/pages/images/user.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'user_h.png',
- pagePath: 'pages/user/user',
- click: 'goUser',
- channel: 'user',
- index: 3,
- show: true
- }
- ]
- },
- {
- name: 'taoyanxi',
- list: [{
- text: "首页",
- iconPath: "/static/pages/images/home.png",
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'home_h.png',
- iconPathOn: "home.png",
- selectedIconPathOn: 'home_h.png',
- pagePath: 'pages/index/index',
- channel: 'home',
- click: 'goHome',
- index: 1,
- show: true
- },
- {
- text: "产品",
- iconPath: '/static/pages/images/service.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'service_h.png',
- iconPathOn: "service.png",
- selectedIconPathOn: 'service_h.png',
- pagePath: 'pages/service/index',
- click: 'goService',
- channel: 'service',
- index: 2,
- show: true
- },
- {
- text: "我的",
- iconPath: '/static/pages/images/user.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'user_h.png',
- iconPathOn: "user.png",
- selectedIconPathOn: 'user_h.png',
- pagePath: 'pages/user/user',
- click: 'goUser',
- channel: 'user',
- index: 3,
- show: true
- }
- ]
- },
- {
- name: 'yaofang',
- list: [{
- text: "首页",
- iconPath: "/static/pages/images/home.png",
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'home_h.png',
- iconPathOn: "home.png",
- selectedIconPathOn: 'home_h.png',
- pagePath: 'home/index/index_yaofang',
- channel: 'home',
- click: 'goHome',
- index: 1,
- show: true
- },
- {
- text: "分类",
- iconPath: '/static/pages/images/sort.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'sort_h.png',
- iconPathOn: "sort.png",
- selectedIconPathOn: 'sort_h.png',
- pagePath: 'pages/service/index',
- click: 'goService',
- channel: 'service',
- index: 2,
- show: true
- },
- {
- text: "购物车",
- iconPath: '/static/pages/images/cart.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'cart_h.png',
- iconPathOn: "cart.png",
- selectedIconPathOn: 'cart_h.png',
- pagePath: 'pages/cart/cart?isSwitchTab=true',
- click: 'goCart',
- channel: 'cart',
- index: 3,
- show: true
- },
- {
- text: "我的",
- iconPath: '/static/pages/images/user.png',
- selectedIconPath: '/static/pages/images/' + publics.iconSrc + 'user_h.png',
- iconPathOn: "user.png",
- selectedIconPathOn: 'user_h.png',
- pagePath: 'pages/user/user',
- click: 'goUser',
- channel: 'user',
- index: 4,
- show: true
- }
- ]
- }
- ]
- module.exports = {
- setStorage: setStorage,
- getStorage: getStorage,
- postRequest: postRequest,
- postRequestLoding: postRequestLoding,
- getRequest: getRequest,
- putRequest: putRequest,
- putRequestJson: putRequestJson,
- getRequestKDX: getRequestKDX,
- postRequestKDX: postRequestKDX,
- msg: msg,
- g: g,
- p: p,
- env: env,
- send: send,
- redirectIndex: redirectIndex,
- saveImage: saveImage,
- saveImageToPhotosAlbum: saveImageToPhotosAlbum,
- uploadFile: uploadFile,
- msgConfirm: msgConfirm,
- getConfig: getConfig,
- load: load,
- isLogin: isLogin,
- isLogins: isLogins,
- isAuthFn:isAuthFn,
- payOrder: payOrder,
- payOrders: payOrders,
- receipt: receipt,
- getLocation: getLocation,
- scopeAddress: scopeAddress,
- isAuth: isAuth,
- alertMsg: alertMsg,
- getToken: getToken,
- loadIng: loadIng,
- removeStorage: removeStorage,
- public: publics,
- header: header,
- // gettmplIds: gettmplIds,
- excludeSpecial: excludeSpecial,
- tab: tab,
- msgConfirmText: msgConfirmText,
- silenceLogin: silenceLogin,
- getWXUserProfile: getWXUserProfile,
- updataWxInfos: updataWxInfos,
- saveBehavior: saveBehavior,
- getBehavior: getBehavior,
- getBehaviorCount: getBehaviorCount,
- getBehaviorUpdate: getBehaviorUpdate,
- isTabPage: isTabPage,
- toTabBar: toTabBar,
- updataWxInfos: updataWxInfos,
- initIMChat: initIMChat,
- getIMToken: getIMToken,
- jumpConversation: jumpConversation,
- jumpSingleChatRoom: jumpSingleChatRoom,
- onNetworkStatusChangeIM: onNetworkStatusChangeIM,
- payAppOrder: payAppOrder,
- savePortAndSource: savePortAndSource,
- getUserPort: getUserPort,
- getWebchatAppId: getWebchatAppId,
- checkPaySuccess: paySuccess,
- getwxConfig:getwxConfig
- }
|