initialize.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import {
  2. getThirdWebAddress,
  3. getThirdWebAddressByMessage,
  4. facResultHandle
  5. } from '@/api/government.js';
  6. import $CONFIG from "@/config/global.config.js"
  7. import keys from "./keys.js";
  8. import config from '@/config/global.config.js'
  9. import Vue from 'vue'
  10. const pathHint = () => {
  11. uni.showToast({
  12. icon: 'none',
  13. title: '敬请期待'
  14. })
  15. }
  16. // const skipApps = (path) => {
  17. // if (path === "#") {
  18. // pathHint()
  19. // return false
  20. // }
  21. // uni.navigateTo({
  22. // url: `/pages/web-view/Apps?path=${encodeURIComponent(path)}`
  23. // });
  24. // }
  25. const skipAggregation = (themeId) => {
  26. if (themeId) {
  27. try {
  28. uni.navigateTo({
  29. url: `/pages/government/Aggregate-page?themeId=${themeId}`,
  30. fail: err => {
  31. console.log('000000000', err)
  32. }
  33. });
  34. } catch (err) {
  35. console.log('未配置页面')
  36. }
  37. } else {
  38. uni.showToast({
  39. icon: 'none',
  40. title: '聚合页面配置错误'
  41. })
  42. }
  43. }
  44. const skipWeb = (path, title) => {
  45. if (path === "#") {
  46. pathHint()
  47. return false
  48. }
  49. uni.navigateTo({
  50. url: `/pages/web-view/Apps?path=${encodeURIComponent(path)}&title=${title || ''}`,
  51. complete: () => {
  52. oldApps = null;
  53. }
  54. });
  55. }
  56. const InternalPage = {
  57. home: '/pages/home',
  58. zhengwujihe: '/pages/government/more-app',
  59. moreApps: '/pages/government/more-app',
  60. shenghuojihe: '/pages/government/more-app',
  61. call_center: '/pages/government/customer-center',
  62. shop: '/pages/index/lidaPage',
  63. myorder: '/pages/government/myOrder'
  64. }
  65. const tabbarPage = [
  66. 'pages/home', 'pages/government/map', 'pages/government/discovery', 'pages/government/mine'
  67. ]
  68. const antiShake = true; // 是否开启防抖
  69. let oldApps = null;
  70. let openApp = null;
  71. const getAppLocation = (id, name) => {
  72. openApp = id
  73. getThirdWebAddress(id).then(res => {
  74. try {
  75. // 只打开最新点击的应用
  76. if (antiShake && openApp !== id) {
  77. throw new Error('')
  78. }
  79. // type 应用类型(内部1/第三方h5应用2/第三方微信小程序3)
  80. if (res.data.address === "#") {
  81. pathHint()
  82. throw new Error('')
  83. }
  84. if (res.data.type == 1) {
  85. if (tabbarPage.includes(res.data.address)) {
  86. uni.switchTab({
  87. url: res.data.address,
  88. complete: () => {
  89. oldApps = null;
  90. }
  91. })
  92. } else {
  93. uni.navigateTo({
  94. url: res.data.address,
  95. complete: () => {
  96. oldApps = null;
  97. }
  98. })
  99. }
  100. } else if (res.data.type == 2) {
  101. if (res.data.address) {
  102. skipWeb(res.data.address, name)
  103. }
  104. } else {
  105. Vue.prototype.$openWXminiprogram(res.data);
  106. oldApps = null;
  107. return false
  108. // plus.share.getServices(result => {
  109. // let sweixin = '';
  110. // for (var i = 0; i < result.length; i++) {
  111. // let t = result[i];
  112. // if (t.id == 'weixin') {
  113. // sweixin = t;
  114. // }
  115. // }
  116. // if (sweixin) {
  117. // sweixin.launchMiniProgram({
  118. // id: res.data.appletOriginalId, // 要跳转小程序的原始ID
  119. // path: res.data.address
  120. // },
  121. // // 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数
  122. // );
  123. // } else {
  124. // // 没有获取到微信分享服务
  125. // uni.showToast({
  126. // icon: 'none',
  127. // title: '当前环境不支持微信操作!'
  128. // })
  129. // }
  130. // }, error => {
  131. // // 获取分享服务列表失败
  132. // console.log(error)
  133. // })
  134. }
  135. } catch (e) {
  136. //TODO handle the exception
  137. oldApps = null;
  138. }
  139. }).catch(err => {
  140. console.log('请求直接偶遇 catch', err, openApp, id)
  141. oldApps = null;
  142. })
  143. }
  144. // 人脸识别回跳方法
  145. const facRedirectHandle = (data, resData) => {
  146. facResultHandle({
  147. ...data,
  148. verifyResult: resData.data
  149. }).then(res => {
  150. let url = ''
  151. if (res.code == 200) {
  152. let result = res.data;
  153. console.log(result)
  154. url = `${data.redirect}?isFac=${result.isFac}&result=${result.result}`
  155. } else {
  156. url = `${data.redirect}?isFac=false`
  157. }
  158. skipWeb(url)
  159. })
  160. }
  161. const getMessageAppLocation = (appId, messageAddress) => {
  162. getThirdWebAddressByMessage(appId, messageAddress).then(res => {
  163. if (res.data.address) {
  164. skipWeb(res.data.address)
  165. }
  166. }).catch(err => {})
  167. }
  168. const filePathHandle = (path, str) => {
  169. if (path.startsWith(str)) {
  170. return path
  171. }
  172. return config.imgURL + path
  173. }
  174. export default {
  175. install(Vue) {
  176. Vue.prototype.$keys = keys;
  177. Vue.prototype.$skeletonTime = 500; // 骨架屏幕过度事件
  178. Object.defineProperty(Vue.prototype, '$skipWeb', {
  179. value: (path, title) => {
  180. skipWeb(path, title)
  181. }
  182. });
  183. /**
  184. * 图片连接封装, 地址拼接
  185. *
  186. */
  187. Object.defineProperty(Vue.prototype, '$getImgPath', {
  188. value: (path = '') => {
  189. // let img = ""
  190. // if (path.indexOf('http://') !== 0 && path.indexOf('https://') !== 0) {
  191. // if (path.indexOf('/') !== 0) {
  192. // img = $CONFIG.imgURL + '/' + path
  193. // } else {
  194. // img = $CONFIG.imgURL + path
  195. // }
  196. // }
  197. // return img || path
  198. return path
  199. }
  200. // value: (path = '', str = 'http') => {
  201. // return filePathHandle(path, str)
  202. // }
  203. })
  204. Object.defineProperty(Vue.prototype, '$onDesensitization', {
  205. value: (type, text) => {
  206. let val = '';
  207. if (text) {
  208. switch (type) {
  209. case 'name':
  210. let arr = text.split("")
  211. arr[0] = "*"
  212. val = `${arr.join("")}`;
  213. // val = `**${text.substring(text.length - 1)}`;
  214. break;
  215. case 'tel':
  216. const tel = '' + text;
  217. val = tel.replace(tel.substring(3, 7), "****")
  218. break;
  219. }
  220. }
  221. return val
  222. }
  223. })
  224. Object.defineProperty(Vue.prototype, '$editorFile', {
  225. value: (content = '') => {
  226. // const regex = /src="([^"]*)"/g;
  227. const regex = /<img\s+[^>]*src="([^"]*)"/g;
  228. const updatedText = content.replace(regex, `<img src="${$CONFIG.imgURL}$1"`);
  229. return updatedText
  230. }
  231. })
  232. /**
  233. * 广告,金刚区,聚合页的模型,新闻内部页的外部第三方应用 跳转逻辑
  234. *
  235. * 内部页 | 外部链接 | 内部资源 |,如果是内部页会有内部页标识,
  236. * 前端自己定位(如 index 对应page/page/index);如果外部链接,
  237. * 会有外部链接地址(http或https的地址)应该是直接open;如果是内部资源,
  238. * 除应用资源之外的资源如新闻,前端自己把资源id结合app的实际路由去拼接后跳转,
  239. * 只有是应用要调用后面的接口来获取实际的地址,获取后再open后台给的地址。
  240. *
  241. * jumpType 跳转类型(内部页面0、外部链接1,内部资源模型2)
  242. * 内部页面标识 innerPageCode
  243. * 外部链接地址 outsideAddress
  244. * resourceModel 内部资源具体模型(无0,应用1,聚合主题2,新闻3)
  245. * 内部资源id resourceModelId
  246. * 内部资源标题 resourceModelTitle
  247. *
  248. * jumpType=2,resourceModel=1 的时候 resourceModelId的值才是应用的id
  249. *
  250. *
  251. * // createTime:"2023-12-22 10:37:40"
  252. // icon:"http://sly2020.oss-cn-beijing.aliyuncs.com/2023/12/22/68a8221c72194db68198c35eafe8db05.png"
  253. // id:2
  254. // innerPageCode:null
  255. // jumpType:2
  256. // locationId:2
  257. // name:"金刚区名称"
  258. // outsideAddress:"#"
  259. // remark:"金刚区备注"
  260. // resourceModel:1
  261. // resourceModelId:"1737779725272748032"
  262. // resourceModelTitle:"测试应用"
  263. // sequence:1
  264. // status:true
  265. // updateTime:"2023-12-22 11:20:27"
  266. *
  267. * type: 特殊情况,
  268. * 1. 聚合页面
  269. */
  270. Object.defineProperty(Vue.prototype, '$openPage', {
  271. value: (dataVal = {}, type = null) => {
  272. if (antiShake && oldApps && oldApps.id === dataVal.id) {
  273. // 防止频繁点击
  274. console.log('开启防抖')
  275. return false
  276. }
  277. oldApps = dataVal;
  278. if (type) {
  279. switch (type) {
  280. case 1:
  281. // 聚合页面
  282. skipAggregation(dataVal);
  283. break;
  284. }
  285. oldApps = null;
  286. } else if (dataVal.hasOwnProperty('jumpType')) {
  287. // 金刚区
  288. const {
  289. jumpType
  290. } = dataVal
  291. try {
  292. if (jumpType === undefined || jumpType === null) {
  293. if (dataVal.resourceModel == 3) {
  294. uni.navigateTo({
  295. url: `/pages/news/news_detail?informationId=${dataVal.resourceModelId}`
  296. })
  297. }
  298. throw new Error(1);
  299. }
  300. switch (Number(jumpType)) {
  301. case 0:
  302. // 内部页面
  303. const {
  304. innerPageCode
  305. } = dataVal;
  306. let path = ``;
  307. switch (innerPageCode) {
  308. case "zhengwujihe":
  309. path =
  310. `${InternalPage.moreApps}?key=${keys.ZW_MOER_APPS}&title=${dataVal.name || '更多服务'}`;
  311. break;
  312. case "shenghuojihe":
  313. path =
  314. `${InternalPage.moreApps}?key=${keys.SH_MOER_APPS}&title=${dataVal.name || '更多服务'}`;
  315. break;
  316. default:
  317. path = InternalPage[innerPageCode];
  318. break;
  319. }
  320. // console.log(path)
  321. try {
  322. uni.navigateTo({
  323. url: path,
  324. fail: err => {
  325. // console.log('跳转 = ' , err)
  326. uni.switchTab({
  327. url: path
  328. });
  329. }
  330. });
  331. } catch (err) {
  332. console.log('未配置页面')
  333. }
  334. break;
  335. case 1:
  336. // 外部链接
  337. const {
  338. outsideAddress,
  339. name
  340. } = dataVal;
  341. skipWeb(outsideAddress, name)
  342. break;
  343. case 2:
  344. // 内部资源模型
  345. if (dataVal.resourceModel === 1) {
  346. // 获取应用地址
  347. getAppLocation(dataVal.resourceModelId, dataVal.name)
  348. return
  349. } else if (dataVal.resourceModel === 2) {
  350. // 聚合页面
  351. skipAggregation(dataVal.resourceModelId)
  352. } else if (dataVal.resourceModel === 3) {
  353. // 新闻页面 dataVal.resourceModelId
  354. uni.navigateTo({
  355. url: `/pages/news/news_detail?informationId=${dataVal.resourceModelId}`
  356. })
  357. } else if (dataVal.resourceModel === 4) {
  358. // 游戏大转盘
  359. uni.navigateTo({
  360. url: `/pages/game/Lottery?activityId=${dataVal.resourceModelId}`
  361. })
  362. }
  363. break;
  364. }
  365. } catch (e) {
  366. const TYPE = e.message
  367. let message = ''
  368. switch (Number(TYPE)) {
  369. case 1:
  370. message = '系统设置错误,请联系管理员';
  371. break;
  372. }
  373. if (message) uni.showToast({
  374. title: message,
  375. icon: 'none'
  376. })
  377. }
  378. oldApps = null;
  379. } else {
  380. getAppLocation(dataVal.thirdApplicationId, dataVal.name);
  381. return
  382. }
  383. }
  384. });
  385. // Object.defineProperty(Vue.prototype, '$ApiCallback', {
  386. // value: async (Api, params) => {
  387. // const {
  388. // path,
  389. // method
  390. // } = Api;
  391. // let data = null
  392. // switch (method) {
  393. // case 'get':
  394. // data = await http.get(path, params);
  395. // break;
  396. // case 'post':
  397. // data = await http.post(path, params);
  398. // break;
  399. // }
  400. // if (data && data.code === 200) {
  401. // return Promise.resolve(data)
  402. // } else {
  403. // return Promise.reject(2)
  404. // }
  405. // }
  406. // });
  407. /**
  408. * 校验是否已登录
  409. * redirect : 是否需要重定向,true时直接跳转登录页面,false 则不跳转,通过Promise.reject返回错误,页面自行处理,
  410. * 默认为true
  411. */
  412. Object.defineProperty(Vue.prototype, '$VerifyLogin', {
  413. value: (redirect = true) => {
  414. return Promise.resolve()
  415. // return Promise.reject(345)
  416. }
  417. });
  418. // export const ApiCallback = async (Api, params) => {
  419. // const {
  420. // path,
  421. // method
  422. // } = Api;
  423. // let data = null
  424. // switch (method) {
  425. // case 'get':
  426. // data = await http.get(path, params);
  427. // break;
  428. // case 'post':
  429. // data = await http.post(path, params);
  430. // break;
  431. // }
  432. // if (data && data.code === 200) {
  433. // return Promise.resolve(data)
  434. // } else {
  435. // return Promise.reject(2)
  436. // }
  437. // }
  438. /**
  439. * 消息跳转
  440. * type
  441. * applicationId 第三方应用 appid
  442. * linkAddress 第三方应用地址
  443. */
  444. Object.defineProperty(Vue.prototype, '$openMessage', {
  445. value: (messageInfo) => {
  446. if (messageInfo.type == 1) {
  447. getMessageAppLocation(messageInfo.applicationId, messageInfo.linkAddress)
  448. }
  449. }
  450. });
  451. /**
  452. * 唤醒小程序
  453. * 人脸识别
  454. * typeValue 0 纯唤醒小程序 1 授权登录 2 人脸识别
  455. */
  456. Object.defineProperty(Vue.prototype, '$openWXminiprogram', {
  457. value: (data = {}, typeValue = 0, auth = false) => {
  458. return new Promise((resolve, reject) => {
  459. plus.share.getServices(result => {
  460. let sweixin = '';
  461. for (var i = 0; i < result.length; i++) {
  462. let t = result[i];
  463. if (t.id == 'weixin') {
  464. sweixin = t;
  465. }
  466. }
  467. if (sweixin) {
  468. let id = ''
  469. let path = ''
  470. let type = 0
  471. switch (typeValue) {
  472. case 0:
  473. id = data.appletOriginalId
  474. path = data.address
  475. break;
  476. case 1:
  477. id = 'gh_9b86ebba08b0'
  478. type = 0
  479. path = `/pages/authLogin/authLogin?appName=宜格服务`
  480. break;
  481. case 2:
  482. id = 'gh_9b86ebba08b0'
  483. type = 0
  484. path =
  485. `/pages/identify/face_indentify?name=${data.realName}&idCardNumber=${data.identityCard}&channel=app`
  486. break;
  487. }
  488. sweixin.launchMiniProgram({
  489. // id:"gh_9b86ebba08b0", // 要跳转小程序的原始ID
  490. // type: 2, // 微信小程序版本类型可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  491. // path: `pages/identify/face_indentify?name=${data.realName}&idCardNumber=${data.identityCard}&channel=app`
  492. id: id,
  493. type: type,
  494. path: path
  495. },
  496. // 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数
  497. res => {
  498. let resData = JSON.parse(res)
  499. if (typeValue == 1) {
  500. resolve(resData)
  501. } else if (typeValue == 2) {
  502. if (auth) {
  503. resolve(resData)
  504. } else {
  505. facRedirectHandle(data, resData)
  506. }
  507. }
  508. },
  509. err => {
  510. console.log(err)
  511. uni.showToast({
  512. icon: 'none',
  513. title: '当前环境不支持微信操作!'
  514. })
  515. }
  516. );
  517. } else {
  518. // 没有获取到微信分享服务
  519. uni.showToast({
  520. icon: 'none',
  521. title: '当前环境不支持微信操作!'
  522. })
  523. }
  524. }, error => {
  525. // 获取分享服务列表失败
  526. console.log(error)
  527. })
  528. })
  529. }
  530. });
  531. /**
  532. * 任务状态说明
  533. * checkStatus 审状态(0未提交,1待审核,2驳回,3审核通过)
  534. */
  535. Object.defineProperty(Vue.prototype, '$TaskStatusText', {
  536. value: (status) => {
  537. let text = "";
  538. if (status >= 0) {
  539. switch (status) {
  540. case 0:
  541. text = "未提交";
  542. break;
  543. case 1:
  544. text = "待审核";
  545. break;
  546. case 2:
  547. text = "驳回";
  548. break;
  549. case 3:
  550. text = "审核通过";
  551. break;
  552. }
  553. }
  554. return text
  555. }
  556. })
  557. }
  558. }