| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503 |
- const app = getApp();
- let WebIM = (wx.WebIM = require("../hxChatSDK/utils/WebIM")["default"]);
- import JSEncrypt from '../utils/jsencrypt.js'
- const env = {
- NODE_ENV: 'pota',
- dev: {
- // apiUrl: 'https://rsapi.zhiqiyun.net'
- apiUrl: 'https://unwx.e-chinalife.com/hkttest',
- },
- prd: {
- apiUrl: 'https://unwx.e-chinalife.com/hktonline'
- },
- pota: {
- // apiUrl: 'http://192.168.110.98:8098'
- // apiUrl: 'http://192.168.110.180:8098' ,//f
- // apiUrl: 'http://192.168.110.182:8094' ,//z
- // apiUrl: 'http://192.168.110.176:8098' //y
- // apiUrl: 'http://192.168.110.117:8098'//l
- // apiUrl: 'http://192.168.110.216:8098'
- apiUrl: 'http://192.168.110.180:8098' ,//wjg
- }
- }
- var header = {
- 'content-type': 'application/x-www-form-urlencoded',
- }
- /**小程序配置 */
- const publics = {
- picUrls: 'https://zhiqiyun.oss-cn-hangzhou.aliyuncs.com/static/', //图片地址
- 'copyrighttitle': '智企云', //底部版权公司名称
- 'copyrighttel': '400-698-5980', //底部版权服务电话
- 'copyrightlogo': 'zhiqiyun', //底部版权 logo 文件名
- 'mapLBSKEY': 'CBRBZ-5SHKL-3NCPX-EP5MQ-B57M6-CWFUU',
- 'iconSrc': 'red/',
- 'titleTopBgColor': '#FFF',
- // 小程序ID wxe7bec198ecfe1162
- // 文章栏目code
- 'fxCode': 'faxian', //发现
- 'xbrmCode': 'xiaobairumen', //小白入门
- 'tbalCode': 'toubaoanli', //投保案例
- 'lpalCode': 'lipeianli', //理赔案例
- 'gfdtCode':'gfdt',//官方动态
-
- // 加密
- 'RSAKEY':"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDehEEc+q5s+m8c7fajkuzh5Cj/obdzngBZZmOHUcc3ck3oSfQQgs/bUoVCccJqbSSL4Z2+/BEq4wNeSeIH4nb26Euml2HhtFzVHej+of2r6NR+zB2DVbddoHJxcvb3kTC5KWPEZ6pN9aw4guMk2d78ZhWdfYSkmuNAebytSyc7ZQIDAQAB"
- }
- /*
- * 获取token
- */
- const getToken = (success) => {
- let token = getStorage('AUTH_TOKEN');
- if (token) {
- success.call(this, token);
- return false;
- } else {
- loadToken(data => {
- success.call(this, data);
- });
- }
- }
- const loadToken = (success) => {
- let that = this
- uni.request({
- url: env[env.NODE_ENV].apiUrl + '/api/access_token',
- data: {},
- method: 'get',
- header: header,
- success(json) {
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code !== 0) return msg(json.data.msg)
- setStorage('AUTH_TOKEN', json.data.data);
- success.call(that, json.data.data);
- },
- fail() {
- msg('access_token 获取失败');
- }
- })
- }
- /**
- * 微信小程序静默授权登录
- * @param {*} parentId
- * @param {*} merchantId
- */
- const silenceLogin = (parentId, merchantId) => {
- // #ifdef MP-WEIXIN
- return new Promise((resolve, reject) => {
- if (!isLogins(false)) { //未登录
- uni.login({
- success(res) {
- console.log('静默授权登录>>>', res);
- let params = {
- code: res.code,
- parentId: parentId ? parentId : '',
- merchantId: merchantId ? merchantId : ''
- }
- postRequest('/api/v3/silence/login', params, data => {
- if (data.token) setStorage('AUTH_TOKEN', data.token);
- getRequest('/api/user/info', {}, suc => {
- data.isDistriUser = suc.isDistriUser;
- setStorage('userInfo', data);
- getIMToken(false);
- getIMChatMsg()
- });
- resolve();
- });
- }
- });
- } else {
- initIMChat();
- getIMChatMsg()
- resolve();
- }
- });
- // #endif
- }
- const getsysConfig = (upData)=>{
- // upData true刷新缓存系统参数
- return new Promise((r,j)=>{
- if(upData){
- getRequest('/api/other/config', {}, res => {
- setStorage('configRes', JSON.stringify(res));
- r(res)
- });
- }else{
- if(getStorage('configRes')) r(JSON.parse(getStorage('configRes')))
- else{
- getRequest('/api/other/config', {}, res => {
- setStorage('configRes', JSON.stringify(res));
- r(res)
- });
- }
- }
- })
- }
- /**
- * 初始化 IMsdk
- */
- const initIMChat = () => {
- var user = getStorage('userInfo');
- if (user) {
- var imToken = getStorage('imToken');
- if (imToken) {
- //初始化IM
- uni.setStorage({
- key: "myUsername",
- data: 'rs_' + user.id
- });
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: 'rs_' + user.id,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- } else {
- getRequest('/api/im/msg/userToken', {}, suc => {
- setStorage('imToken', suc);
- uni.setStorage({
- key: "myUsername",
- data: 'rs_' + user.id
- });
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: 'rs_' + user.id,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- });
- }
- }
- }
- const getIMToken = (isUpdatToken) => {
- var user = getStorage('userInfo');
- getRequest('/api/im/msg/userToken', {}, suc => {
- setStorage('imToken', suc);
- if (isUpdatToken) {
- //更新token
- uni.setStorage({
- key: "myUsername",
- data: 'rs_' + user.id
- });
- getApp().globalData.conn.open({
- user: 'rs_' + user.id,
- accessToken: getStorage('imToken'),
- });
- getApp().globalData.onLoginSuccess(uni.getStorageSync("myUsername"));
- } else {
- initIMChat();
- }
- }, true);
- }
- const getIMChatMsg = ()=>{
- uni.getStorageInfo({
- success: function(res) {
- let storageKeys = res.keys;
- let haveHistoryChatMsgKeys = false
- storageKeys.forEach((item) => {
- let key = item
- if(item==="myUsername"){
- uni.setStorageSync(item,uni.getStorageSync(item).replace('RS_','rs_'))
- }
- if(item.indexOf('imUserInfo')>-1){
- uni.setStorageSync(item.replaceAll('RS_','rs_'),uni.getStorageSync(item))
- if(item!==key){
- uni.removeStorageSync(key)
- }
- }
- if(item.indexOf('rendered')>-1){
- let key = item
- haveHistoryChatMsgKeys = true
- let rs = uni.getStorageSync(item)
- rs.map(item=>{
- item.info.from = item.info.from.replaceAll('RS_','rs_')
- item.info.to = item.info.to.replaceAll('RS_','rs_')
- item.username = item.username.replaceAll('RS_','rs_')
- item.yourname = item.yourname.replaceAll('RS_','rs_')
- })
- uni.setStorageSync(item.replaceAll('RS_','rs_'),rs)
- if(item!==key){
- uni.removeStorageSync(key)
- }
- }
- });
- if(haveHistoryChatMsgKeys){
-
- }else{
- getRequest('/api/im/msg/pageWechat', {}, suc => {
- if(suc.length>0){
- suc.map(item=>{
- console.log('skey:getRequest')
- let skey = ''
- if(item[0].info.from===('rs_'+getStorage('userInfo').id)){
- skey = "rendered_"+item[0].info.to + item[0].info.from
- }else{
- skey = "rendered_"+item[0].info.from + item[0].info.to
- }
- if(skey) {
- console.log('skey:',skey)
- console.log('skey item:',item)
- item.forEach(iitem=>{
- if(iitem.msg.type=='txt'){
- iitem.msg.data = WebIM.parseEmoji(iitem.msg.data.toString().replace(/\n/gm, ""));
- }
- })
- console.log('WebIM.parseEmoji',item)
- uni.setStorageSync(skey,item)
- }
- if(item[0].msg.extTo){
- console.log('item[0].msg.extTo',item[0].msg.extTo)
- let key = item
- uni.setStorageSync('imUserInfo_rs_'+item[0].msg.extTo.id,{
- nickName:item[0].msg.extTo.nickName,
- id:item[0].msg.extTo.id,
- avatar:item[0].msg.extTo.avatar
- })
- }
- if(item[0].msg.ext){
- console.log('item[0].msg.ext',item[0].msg.ext)
- let key = item
- uni.setStorageSync('imUserInfo_rs_'+item[0].msg.ext.id,{
- nickName:item[0].msg.ext.nickName,
- id:item[0].msg.ext.id,
- avatar:item[0].msg.ext.avatar
- })
- }
- uni.setStorageSync('imUserInfo_rs_'+getStorage('userInfo').id,{
- nickName:getStorage('userInfo').nickName,
- id:getStorage('userInfo').id,
- avatar:getStorage('userInfo').avatar
- })
- })
- }
- }, false);
- }
- },
- });
- }
- /**
- * 跳转进入消息列表
- */
- const jumpConversation = () => {
- if (!isLogins(true)) { //未登录
- return;
- }
- getIMToken(true);
- }
- 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) => {
- let postData = data
- getToken(token => {
- if (!isLoad) uni.showNavigationBarLoading();
- header.authorityToken = token;
- // if (url.indexOf('/v3') != -1 || url.indexOf('/paper/create') != -1) {
- // header['content-type'] = 'application/json;charset=UTF-8'
- // } else {
- header['content-type'] = 'application/json;charset=UTF-8'
- // }
-
- if(url=='/api/user/userInfoById'||url=='/api/visiting/card/info'){
- if(data.id){
- let encrypt = new JSEncrypt()
- encrypt.setPublicKey(publics.RSAKEY)
- data.id = encrypt.encrypt(data.id)
- }
- if(data.userId){
- let encrypt = new JSEncrypt()
- encrypt.setPublicKey(publics.RSAKEY)
- data.userId = encrypt.encrypt(data.userId)
- }
- }
-
- uni.request({
- url: env[env.NODE_ENV].apiUrl + url,
- data: clearValueEmpty(data),
- method: method,
- header: header,
- success(json) {
- if (!isLoad) uni.hideNavigationBarLoading();
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code === 10021 || json.data.code === 10020) {
- // console.log("第二次执行")
- removeStorage('AUTH_TOKEN');
- removeStorage('userInfo');
- 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);
- }
-
- try{
- // 用户授权手机号日志
- if(url=='/api/weixin/mobile'){
- let sys = uni.getSystemInfoSync()
- let dataP = {
- type:3,
- model: sys.model,
- os: sys.osName,
- osVersion: sys.osVersion
- }
- postRequest('/api/log/authorize/save',dataP,res=>{
-
- })
- }
- // 用户授权昵称头像日志
- if(url=='/api/user/save' && (postData.avatar || postData.nickName || postData.cardNo || postData.areaAdd || postData.address)){
- let sys = uni.getSystemInfoSync()
- let dataP = {
- type:'',
- model: sys.model,
- os: sys.osName,
- osVersion: sys.osVersion
- }
- let dpt = []
- let dptcontent = []
- if(postData.nickName) {
- dpt.push(1)
- dptcontent.push(postData.nickName)
- }
- if(postData.avatar) {
- dpt.push(2)
- dptcontent.push(postData.avatar)
- }
- if(postData.cardNo) {
- dpt.push(4)
- dptcontent.push(postData.cardNo)
- }
- if(postData.areaAdd||postData.address) {
- dpt.push(5)
- dptcontent.push((postData.areaAdd?postData.areaAdd:'')+(postData.address?postData.address:''))
- }
- dataP.type = dpt.join(',')
- dataP.content = dptcontent.join(',')
- if(dpt.length>0){
- postRequest('/api/log/authorize/save',dataP,res=>{
-
- })
- }
- }
- }catch(e){
- //TODO handle the exception
- }
-
- success.call(this, data);
- },
- fail() {
- if (!isLoad) uni.hideNavigationBarLoading();
- },
- // 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/json;charset=UTF-8'
- baseRequest(url, data, 'post', success, isLoad);
- }
- const postRequestLoding = (url, data, success, isLoding) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'post', success, false, isLoding);
- }
- /**GET请求 */
- const getRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'get', success, isLoad);
- }
- /**Put请求 */
- const putRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- 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)
- }
- /**
- * 上传文件
- * @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': 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();
- // 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)
- if (currentUrl == 'pages/authorize/authorize') {
- console.log('当前已经处于登录页面,不在向下执行跳转');
- return
- }
- }
- }
- }
- let redirectUrl = '/pages/authorize/authorize' + (params ? params : '');
- // console.log("登陆拦截")
- uni.navigateTo({
- url: redirectUrl
- })
- 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 = (isGoLogin) => {
- let userInfo = getStorage('userInfo');
- if (!userInfo) {
- if (isGoLogin) {
- redirectIndex();
- }
- return false;
- }
- return true;
- }
- 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) => {
- var loctionAddressMap = getStorage('loctionAddressMap');
- var datas = {
- id: id
- };
- if (loctionAddressMap) {
- datas.province = loctionAddressMap.province;
- datas.city = loctionAddressMap.city;
- };
- if (getStorage('isVideoScene')) {
- uni.checkBeforeAddOrder({
- success(res) {
- console.log('下单前置检查', res)
- let data = res.data;
- data.requiredFundType = 0;
- datas.sceneCheckStr = JSON.stringify(data);
- wexinPay(datas, success)
- },
- })
- } else {
- wexinPay(datas, success)
- }
- }
- //支付中或已支付
- 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)
- }, 500);
- }
- // 支付失败回调
- const payFail = (id) => {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- }
- const wexinPay = (datas, success) => {
- 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)
- const sceneCheckStr = datas.sceneCheckStr;
- if (sceneCheckStr && JSON.parse(sceneCheckStr).requiredFundType === 1) {
- 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)
- }
- })
- } 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)
- }
- })
- }
- 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
- }
- //微信支付订单公共方法
- 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
- }
- //微信支付订单公共方法 ==活动
- 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 => {
- uni.redirectTo({
- url: '/mine/activity/activity',
- })
- })
- console.log(res);
- }
- })
- 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() {
- 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;
- }
- // 数字单位格式化
- function unitConverter(num) {
- // text 数字+单位 number格式化后的数字 unit单位
- console.log(num)
- if (!num || isNaN(num)) {
- return {
- text: 0,
- number: 0,
- unit: ''
- }
- }
- num = Number(num)
- if (Math.abs(num) > 100000000) {
- return {
- text: (num / 100000000).toFixed(2) + '亿',
- number: (num / 100000000).toFixed(2),
- unit: '亿'
- }
- } else if (Math.abs(num) > 10000) {
- return {
- text: (num / 10000).toFixed(2) + '万',
- number: (num / 10000).toFixed(2),
- unit: '万'
- }
- } else {
- return {
- text: num,
- number: num,
- unit: ''
- }
- }
- }
- // 行为操作
- const saveBehavior = (params, success) => {
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、海报
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知 13、素材 15、科室 16、海报 20、医生 21日历、探索 47评价
- postRequest('/api/v3/behavior/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、用户须知 13、素材 15、科室 16、海报 20、医生 21日历、探索 47评价
- console.log('行为')
- getRequest('/api/v3/behavior/get', params, data => {
- success.call(this, data)
- })
- }
- /**
- * @Description:
- * @author: xionghaojie
- * @param bindId 操作对象ID(如果是页面不需要传)
- * @param type 用户行为操作对象(1.名片 2.活动 3.文章 4.社区页面 5.海报 6.点击发现页面 7.点击首页页面 8.点击我的页面 10.聊一聊 11.电话 12.微信 13.通讯录 14.评价名片)
- * @param behavior 用户行为(1.关注 2.收藏 3.点赞 4.浏览 5.确认 6.分享 7.发布 8.评价 9.投票 10.点击 11.取消关注 12.取消点赞 13.评价 14.保存通讯录 15.聊一聊 16.加入)
- * @param content 用户行为内容(非必填)
- * @param shareUid 用户打开浏览时转发人id(非必填)
- * @param browsingDuration 用户浏览时长(非必填,单位s)
- * @return
- * @createTime: 2023-10-16 10:48:32
- */
- const saveBehaviorNew = async (bindId,type,behavior,content, success,shareUid,browsingDuration) => {
- let params = {
- uid:'',
- bindId:bindId,
- behavior:behavior,
- type:type,
- ip:'',//ip
- manufacturer:'',
- model:'',//设备型号
- os:'',//操作系统
- osVersion:'',//操作系统版本
- shareUid:shareUid?shareUid:'',
- browsingDuration:browsingDuration?browsingDuration:''
- }
- await new Promise((resolve,reject)=>{
- uni.getSystemInfoAsync({
- success(res) {
- console.log(res)
- params.manufacturer = res.brand //手机牌子
- params.model = res.model
- params.os = res.system
- params.osVersion = res.version
- resolve()
- },
- fail(error){
- console.log('getSystemInfoSync error',error)
- resolve()
- }
- })
- })
- params.uid = getStorage('userInfo')?getStorage('userInfo').id:''
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、海报
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知 13、素材 15、科室 16、海报 20、医生 21日历、探索 47评价
- postRequest('/api/behaviorNew/save', params, data => {
- if(success)
- success.call(this, data)
- })
- }
- /**
- * 跳入聊天
- * @param {Object} userId 对方用户ID
- * @param {Object} avatar 对方用户头像
- * @param {Object} realName 对方用户名称
- */
- const jumpSingleChatRoom = function(userId, avatar, realName) {
- var my = uni.getStorageSync("myUsername");
- var nameList = {
- myName: my,
- your: 'rs_' + userId
- };
- uni.setStorage({
- key: 'imUserInfo_' + nameList.your,
- data: {
- avatar: avatar,
- id: userId,
- nickName: realName
- }
- });
- uni.navigateTo({
- url: "/chat/chatroom/chatroom?username=" + JSON.stringify(nameList)
- });
- }
- /**
- * text:展示导航名
- * iconPath:未点击显示图标
- * selectedIconPath:选中图标
- * pagePath:页面路径
- * channel:匹配名
- * click:点击事件
- * index:排序
- * show:是否显示
- */
- var selectedIconPath
- if (header.appId == 'ZQ1VK5oc17I387E') {
- selectedIconPath = '/static/pages/images/' + publics.iconSrc + 'yunyao_h.png'
- } else {
- selectedIconPath = '/static/pages/images/' + publics.iconSrc + 'home_h.png'
- }
- var tab = [{
- text: "首页",
- iconPath: "/static/pages/images/home.png",
- selectedIconPath: '/static/pages/images/home_h.png',
- pagePath: 'pages/index/index',
- channel: 'home',
- click: 'goHome',
- index: 1,
- show: true
- },
- {
- text: "活动",
- iconPath: "/static/pages/images/activity.png",
- selectedIconPath: '/static/pages/images/activity_h.png',
- pagePath: 'pages/matchList/index',
- click: 'goMatch',
- channel: 'match',
- index: 2,
- show: true
- },
- {
- text: "社区",
- iconPath: "/static/pages/images/interactive.png",
- selectedIconPath: '/static/pages/images/interactive_h.png',
- pagePath: 'pages/interactive/index',
- click: 'goInteractive',
- channel: 'interactive',
- index: 3,
- show: true
- },
- {
- text: "发现",
- iconPath: "/static/pages/images/found.png",
- selectedIconPath: '/static/pages/images/found_h.png',
- pagePath: 'pages/found/found',
- click: 'goFound',
- channel: 'found',
- index: 3,
- show: true
- },
- {
- text: "我的",
- iconPath: '/static/pages/images/user.png',
- selectedIconPath: '/static/pages/images/user_h.png',
- pagePath: 'pages/user/user',
- click: 'goUser',
- channel: 'user',
- index: 6,
- show: true
- }
- ]
- module.exports = {
- setStorage: setStorage,
- getStorage: getStorage,
- postRequest: postRequest,
- postRequestLoding: postRequestLoding,
- getRequest: getRequest,
- putRequest: putRequest,
- putRequestJson: putRequestJson,
- 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,
- payOrder: payOrder,
- payOrders: payOrders,
- 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,
- saveBehaviorNew:saveBehaviorNew,
- unitConverter: unitConverter,
- initIMChat: initIMChat,
- getIMToken: getIMToken,
- jumpConversation: jumpConversation,
- jumpSingleChatRoom: jumpSingleChatRoom,
- getsysConfig:getsysConfig
- }
|