123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- import {
- getThirdWebAddress,
- getThirdWebAddressByMessage,
- facResultHandle
- } from '@/api/government.js';
- import $CONFIG from "@/config/global.config.js"
- import keys from "./keys.js";
- import config from '@/config/global.config.js'
- import Vue from 'vue'
- const pathHint = () => {
- uni.showToast({
- icon: 'none',
- title: '敬请期待'
- })
- }
- // const skipApps = (path) => {
- // if (path === "#") {
- // pathHint()
- // return false
- // }
- // uni.navigateTo({
- // url: `/pages/web-view/Apps?path=${encodeURIComponent(path)}`
- // });
- // }
- const skipAggregation = (themeId) => {
- if (themeId) {
- try {
- uni.navigateTo({
- url: `/pages/government/Aggregate-page?themeId=${themeId}`,
- fail: err => {
- console.log('000000000', err)
- }
- });
- } catch (err) {
- console.log('未配置页面')
- }
- } else {
- uni.showToast({
- icon: 'none',
- title: '聚合页面配置错误'
- })
- }
- }
- const skipWeb = (path, title) => {
- if (path === "#") {
- pathHint()
- return false
- }
- uni.navigateTo({
- url: `/pages/web-view/Apps?path=${encodeURIComponent(path)}&title=${title || ''}`,
- complete: () => {
- oldApps = null;
- }
- });
- }
- const InternalPage = {
- home: '/pages/home',
- zhengwujihe: '/pages/government/more-app',
- moreApps: '/pages/government/more-app',
- shenghuojihe: '/pages/government/more-app',
- call_center: '/pages/government/customer-center',
- shop: '/pages/index/lidaPage',
- myorder: '/pages/government/myOrder'
- }
- const tabbarPage = [
- 'pages/home', 'pages/government/map', 'pages/government/discovery', 'pages/government/mine'
- ]
- const antiShake = true; // 是否开启防抖
- let oldApps = null;
- let openApp = null;
- const getAppLocation = (id, name) => {
- openApp = id
- getThirdWebAddress(id).then(res => {
- try {
- // 只打开最新点击的应用
- if (antiShake && openApp !== id) {
- throw new Error('')
- }
- // type 应用类型(内部1/第三方h5应用2/第三方微信小程序3)
- if (res.data.address === "#") {
- pathHint()
- throw new Error('')
- }
- if (res.data.type == 1) {
- if (tabbarPage.includes(res.data.address)) {
- uni.switchTab({
- url: res.data.address,
- complete: () => {
- oldApps = null;
- }
- })
- } else {
- uni.navigateTo({
- url: res.data.address,
- complete: () => {
- oldApps = null;
- }
- })
- }
- } else if (res.data.type == 2) {
- if (res.data.address) {
- skipWeb(res.data.address, name)
- }
- } else {
- Vue.prototype.$openWXminiprogram(res.data);
- oldApps = null;
- return false
- // plus.share.getServices(result => {
- // let sweixin = '';
- // for (var i = 0; i < result.length; i++) {
- // let t = result[i];
- // if (t.id == 'weixin') {
- // sweixin = t;
- // }
- // }
- // if (sweixin) {
- // sweixin.launchMiniProgram({
- // id: res.data.appletOriginalId, // 要跳转小程序的原始ID
- // path: res.data.address
- // },
- // // 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数
- // );
- // } else {
- // // 没有获取到微信分享服务
- // uni.showToast({
- // icon: 'none',
- // title: '当前环境不支持微信操作!'
- // })
- // }
- // }, error => {
- // // 获取分享服务列表失败
- // console.log(error)
- // })
- }
- } catch (e) {
- //TODO handle the exception
- oldApps = null;
- }
- }).catch(err => {
- console.log('请求直接偶遇 catch', err, openApp, id)
- oldApps = null;
- })
- }
- // 人脸识别回跳方法
- const facRedirectHandle = (data, resData) => {
- facResultHandle({
- ...data,
- verifyResult: resData.data
- }).then(res => {
- let url = ''
- if (res.code == 200) {
- let result = res.data;
- console.log(result)
- url = `${data.redirect}?isFac=${result.isFac}&result=${result.result}`
- } else {
- url = `${data.redirect}?isFac=false`
- }
- skipWeb(url)
- })
- }
- const getMessageAppLocation = (appId, messageAddress) => {
- getThirdWebAddressByMessage(appId, messageAddress).then(res => {
- if (res.data.address) {
- skipWeb(res.data.address)
- }
- }).catch(err => {})
- }
- const filePathHandle = (path, str) => {
- if (path.startsWith(str)) {
- return path
- }
- return config.imgURL + path
- }
- export default {
- install(Vue) {
- Vue.prototype.$keys = keys;
- Vue.prototype.$skeletonTime = 500; // 骨架屏幕过度事件
- Object.defineProperty(Vue.prototype, '$skipWeb', {
- value: (path, title) => {
- skipWeb(path, title)
- }
- });
- /**
- * 图片连接封装, 地址拼接
- *
- */
- Object.defineProperty(Vue.prototype, '$getImgPath', {
- value: (path = '') => {
- // let img = ""
- // if (path.indexOf('http://') !== 0 && path.indexOf('https://') !== 0) {
- // if (path.indexOf('/') !== 0) {
- // img = $CONFIG.imgURL + '/' + path
- // } else {
- // img = $CONFIG.imgURL + path
- // }
- // }
- // return img || path
- return path
- }
- // value: (path = '', str = 'http') => {
- // return filePathHandle(path, str)
- // }
- })
- Object.defineProperty(Vue.prototype, '$onDesensitization', {
- value: (type, text) => {
- let val = '';
- if (text) {
- switch (type) {
- case 'name':
- let arr = text.split("")
- arr[0] = "*"
- val = `${arr.join("")}`;
- // val = `**${text.substring(text.length - 1)}`;
- break;
- case 'tel':
- const tel = '' + text;
- val = tel.replace(tel.substring(3, 7), "****")
- break;
- }
- }
- return val
- }
- })
- Object.defineProperty(Vue.prototype, '$editorFile', {
- value: (content = '') => {
- // const regex = /src="([^"]*)"/g;
- const regex = /<img\s+[^>]*src="([^"]*)"/g;
- const updatedText = content.replace(regex, `<img src="${$CONFIG.imgURL}$1"`);
- return updatedText
- }
- })
- /**
- * 广告,金刚区,聚合页的模型,新闻内部页的外部第三方应用 跳转逻辑
- *
- * 内部页 | 外部链接 | 内部资源 |,如果是内部页会有内部页标识,
- * 前端自己定位(如 index 对应page/page/index);如果外部链接,
- * 会有外部链接地址(http或https的地址)应该是直接open;如果是内部资源,
- * 除应用资源之外的资源如新闻,前端自己把资源id结合app的实际路由去拼接后跳转,
- * 只有是应用要调用后面的接口来获取实际的地址,获取后再open后台给的地址。
- *
- * jumpType 跳转类型(内部页面0、外部链接1,内部资源模型2)
- * 内部页面标识 innerPageCode
- * 外部链接地址 outsideAddress
- * resourceModel 内部资源具体模型(无0,应用1,聚合主题2,新闻3)
- * 内部资源id resourceModelId
- * 内部资源标题 resourceModelTitle
- *
- * jumpType=2,resourceModel=1 的时候 resourceModelId的值才是应用的id
- *
- *
- * // createTime:"2023-12-22 10:37:40"
- // icon:"http://sly2020.oss-cn-beijing.aliyuncs.com/2023/12/22/68a8221c72194db68198c35eafe8db05.png"
- // id:2
- // innerPageCode:null
- // jumpType:2
- // locationId:2
- // name:"金刚区名称"
- // outsideAddress:"#"
- // remark:"金刚区备注"
- // resourceModel:1
- // resourceModelId:"1737779725272748032"
- // resourceModelTitle:"测试应用"
- // sequence:1
- // status:true
- // updateTime:"2023-12-22 11:20:27"
-
- *
- * type: 特殊情况,
- * 1. 聚合页面
- */
- Object.defineProperty(Vue.prototype, '$openPage', {
- value: (dataVal = {}, type = null) => {
- if (antiShake && oldApps && oldApps.id === dataVal.id) {
- // 防止频繁点击
- console.log('开启防抖')
- return false
- }
- oldApps = dataVal;
- if (type) {
- switch (type) {
- case 1:
- // 聚合页面
- skipAggregation(dataVal);
- break;
- }
- oldApps = null;
- } else if (dataVal.hasOwnProperty('jumpType')) {
- // 金刚区
- const {
- jumpType
- } = dataVal
- try {
- if (jumpType === undefined || jumpType === null) {
- if (dataVal.resourceModel == 3) {
- uni.navigateTo({
- url: `/pages/news/news_detail?informationId=${dataVal.resourceModelId}`
- })
- }
- throw new Error(1);
- }
- switch (Number(jumpType)) {
- case 0:
- // 内部页面
- const {
- innerPageCode
- } = dataVal;
- let path = ``;
- switch (innerPageCode) {
- case "zhengwujihe":
- path =
- `${InternalPage.moreApps}?key=${keys.ZW_MOER_APPS}&title=${dataVal.name || '更多服务'}`;
- break;
- case "shenghuojihe":
- path =
- `${InternalPage.moreApps}?key=${keys.SH_MOER_APPS}&title=${dataVal.name || '更多服务'}`;
- break;
- default:
- path = InternalPage[innerPageCode];
- break;
- }
- // console.log(path)
- try {
- uni.navigateTo({
- url: path,
- fail: err => {
- // console.log('跳转 = ' , err)
- uni.switchTab({
- url: path
- });
- }
- });
- } catch (err) {
- console.log('未配置页面')
- }
- break;
- case 1:
- // 外部链接
- const {
- outsideAddress,
- name
- } = dataVal;
- skipWeb(outsideAddress, name)
- break;
- case 2:
- // 内部资源模型
- if (dataVal.resourceModel === 1) {
- // 获取应用地址
- getAppLocation(dataVal.resourceModelId, dataVal.name)
- return
- } else if (dataVal.resourceModel === 2) {
- // 聚合页面
- skipAggregation(dataVal.resourceModelId)
- } else if (dataVal.resourceModel === 3) {
- // 新闻页面 dataVal.resourceModelId
- uni.navigateTo({
- url: `/pages/news/news_detail?informationId=${dataVal.resourceModelId}`
- })
- } else if (dataVal.resourceModel === 4) {
- // 游戏大转盘
- uni.navigateTo({
- url: `/pages/game/Lottery?activityId=${dataVal.resourceModelId}`
- })
- }
- break;
- }
- } catch (e) {
- const TYPE = e.message
- let message = ''
- switch (Number(TYPE)) {
- case 1:
- message = '系统设置错误,请联系管理员';
- break;
- }
- if (message) uni.showToast({
- title: message,
- icon: 'none'
- })
- }
- oldApps = null;
- } else {
- getAppLocation(dataVal.thirdApplicationId, dataVal.name);
- return
- }
- }
- });
- // Object.defineProperty(Vue.prototype, '$ApiCallback', {
- // value: async (Api, params) => {
- // const {
- // path,
- // method
- // } = Api;
- // let data = null
- // switch (method) {
- // case 'get':
- // data = await http.get(path, params);
- // break;
- // case 'post':
- // data = await http.post(path, params);
- // break;
- // }
- // if (data && data.code === 200) {
- // return Promise.resolve(data)
- // } else {
- // return Promise.reject(2)
- // }
- // }
- // });
- /**
- * 校验是否已登录
- * redirect : 是否需要重定向,true时直接跳转登录页面,false 则不跳转,通过Promise.reject返回错误,页面自行处理,
- * 默认为true
- */
- Object.defineProperty(Vue.prototype, '$VerifyLogin', {
- value: (redirect = true) => {
- return Promise.resolve()
- // return Promise.reject(345)
- }
- });
- // export const ApiCallback = async (Api, params) => {
- // const {
- // path,
- // method
- // } = Api;
- // let data = null
- // switch (method) {
- // case 'get':
- // data = await http.get(path, params);
- // break;
- // case 'post':
- // data = await http.post(path, params);
- // break;
- // }
- // if (data && data.code === 200) {
- // return Promise.resolve(data)
- // } else {
- // return Promise.reject(2)
- // }
- // }
- /**
- * 消息跳转
- * type
- * applicationId 第三方应用 appid
- * linkAddress 第三方应用地址
- */
- Object.defineProperty(Vue.prototype, '$openMessage', {
- value: (messageInfo) => {
- if (messageInfo.type == 1) {
- getMessageAppLocation(messageInfo.applicationId, messageInfo.linkAddress)
- }
- }
- });
- /**
- * 唤醒小程序
- * 人脸识别
- * typeValue 0 纯唤醒小程序 1 授权登录 2 人脸识别
- */
- Object.defineProperty(Vue.prototype, '$openWXminiprogram', {
- value: (data = {}, typeValue = 0, auth = false) => {
- return new Promise((resolve, reject) => {
- plus.share.getServices(result => {
- let sweixin = '';
- for (var i = 0; i < result.length; i++) {
- let t = result[i];
- if (t.id == 'weixin') {
- sweixin = t;
- }
- }
- if (sweixin) {
- let id = ''
- let path = ''
- let type = 0
- switch (typeValue) {
- case 0:
- id = data.appletOriginalId
- path = data.address
- break;
- case 1:
- id = 'gh_9b86ebba08b0'
- type = 0
- path = `/pages/authLogin/authLogin?appName=宜格服务`
- break;
- case 2:
- id = 'gh_9b86ebba08b0'
- type = 0
- path =
- `/pages/identify/face_indentify?name=${data.realName}&idCardNumber=${data.identityCard}&channel=app`
- break;
- }
- sweixin.launchMiniProgram({
- // id:"gh_9b86ebba08b0", // 要跳转小程序的原始ID
- // type: 2, // 微信小程序版本类型可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
- // path: `pages/identify/face_indentify?name=${data.realName}&idCardNumber=${data.identityCard}&channel=app`
- id: id,
- type: type,
- path: path
- },
- // 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数
- res => {
- let resData = JSON.parse(res)
- if (typeValue == 1) {
- resolve(resData)
- } else if (typeValue == 2) {
- if (auth) {
- resolve(resData)
- } else {
- facRedirectHandle(data, resData)
- }
- }
- },
- err => {
- console.log(err)
- uni.showToast({
- icon: 'none',
- title: '当前环境不支持微信操作!'
- })
- }
- );
- } else {
- // 没有获取到微信分享服务
- uni.showToast({
- icon: 'none',
- title: '当前环境不支持微信操作!'
- })
- }
- }, error => {
- // 获取分享服务列表失败
- console.log(error)
- })
- })
- }
- });
- /**
- * 任务状态说明
- * checkStatus 审状态(0未提交,1待审核,2驳回,3审核通过)
- */
- Object.defineProperty(Vue.prototype, '$TaskStatusText', {
- value: (status) => {
- let text = "";
- if (status >= 0) {
- switch (status) {
- case 0:
- text = "未提交";
- break;
- case 1:
- text = "待审核";
- break;
- case 2:
- text = "驳回";
- break;
- case 3:
- text = "审核通过";
- break;
- }
- }
- return text
- }
- })
- }
- }
|