App.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <script>
  2. /* eslint-disable */
  3. import Vue from 'vue';
  4. import request from '@/utils/request'
  5. import {
  6. verifyAccessToken
  7. } from '@/api/login'
  8. import {
  9. mapMutations
  10. } from 'vuex';
  11. // import startPage from './pages/index/startPage'
  12. export default {
  13. async onLaunch() {
  14. //app设置当前语言
  15. var lan = 'zh'
  16. try {
  17. const res = uni.getSystemInfoSync();
  18. lan = res.language
  19. } catch (e) {
  20. console.log('error=' + e)
  21. }
  22. console.log('lan=' + lan);
  23. if (lan !== 'zh' || lan == 'en' || lan !== 'zh-Hans-CN') {
  24. this.$i18n.locale = 'en'
  25. }
  26. if (lan == 'zh-CN' || lan == 'zh' || lan == 'zh-Hans-CN') {
  27. this.$i18n.locale = 'zh'
  28. }
  29. //#ifdef APP-PLUS
  30. let client_info = plus.push.getClientInfo(); //获取客户端clientId(这个id每次重新安装包就会刷新
  31. console.log("xxxxxxxxxxx" + JSON.stringify(client_info));
  32. // #endif
  33. //获取手机属于iOS或者安卓
  34. var platform = uni.getSystemInfoSync().platform;
  35. console.log(platform);
  36. //收到透传消息
  37. //只有APP在线时,才会触发receive事件,透传消息不会触发系统消息,需要创建本地消息
  38. //#ifdef APP-PLUS
  39. plus.push.addEventListener("receive", function(msg) {
  40. console.log("(receive):" + JSON.stringify(msg));
  41. console.log("(receive):" + JSON.stringify(msg.payload));
  42. if (platform == "ios") { //如果是IOS
  43. //plus.push.createMessage(msg.title,msg.content);
  44. var payload = msg.payload;
  45. //【APP离线】收到消息,但没有提醒(发生在一次收到多个离线消息时,只有一个有提醒,但其他的没有提醒)
  46. //【APP在线】收到消息,不会触发系统消息,需要创建本地消息,但不能重复创建。必须加msg.type验证去除死循环
  47. if (msg.aps == null && msg.type == "receive") {
  48. console.log(typeof(payload));
  49. var messageTitle = payload.title;
  50. var messageContent = payload.content;
  51. //创建本地消息,发送的本地消息也会被receive方法接收到,但没有type属性,且aps是null
  52. plus.push.createMessage(messageContent, JSON.stringify(payload), {
  53. title: messageTitle
  54. });
  55. }
  56. } else if (platform == "android") {
  57. var payload = msg.payload;
  58. var messageTitle = payload.title;
  59. var messageContent = payload.content;
  60. console.log("(receive。。。。。):" + payload.url);
  61. //plus.push.createMessage(messageContent, msg, {title: messageTitle});
  62. setTimeout(function() {
  63. uni.navigateTo({
  64. url: payload.url
  65. })
  66. }, 1000)
  67. }
  68. }, false);
  69. //消息点击事件
  70. //【APP在线】,收到透传消息通过,不会提醒至通知栏目,需要发送本地消息,再进行点击触发的点击事件。
  71. //【APP离线】,收到离线透传消息,必须通过Java后台的Intent字符串携带payload,且符合格式才能触发click事件,格式不符合不会触发。
  72. plus.push.addEventListener("click", function(msg) {
  73. console.log('click');
  74. console.log("(click):" + JSON.stringify(msg));
  75. console.log("(click):" + JSON.stringify(msg.payload));
  76. if (platform == "ios") { //如果是IOS
  77. var payload;
  78. if (msg.type == "click") { //APP离线点击包含click属性,这时payload是JSON对象
  79. payload = msg.payload;
  80. } else { //APP在线,收到消息不会包含type属性,这时的payload是JSON字符串,需要转为JSON对象
  81. payload = JSON.parse(msg.payload);
  82. }
  83. if (payload != null || payload != undefined) {
  84. setTimeout(function() {
  85. uni.navigateTo({
  86. url: payload.url
  87. })
  88. }, 1000)
  89. }
  90. }
  91. if (platform == "android") {
  92. setTimeout(function() {
  93. uni.navigateTo({
  94. url: msg.payload.url
  95. })
  96. }, 1000)
  97. }
  98. }, false);
  99. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  100. let BASE_URL = 'https://www.geidcp.com/api'
  101. uni.request({
  102. url: BASE_URL + '/project/appSoftwares/searchIsNew',
  103. method: 'get',
  104. data: {
  105. //当前版本
  106. currentVersion: widgetInfo.version,
  107. //当前软件名称
  108. softwareName: widgetInfo.name,
  109. //系统类型
  110. softwarePlatformTypeDict: plus.os.name
  111. },
  112. success: (result) => {
  113. var data = result.data.data;
  114. if (data.flag == false) {
  115. uni.showModal({
  116. title: '版本更新',
  117. content: '发现新版本请问是否进行更新',
  118. success: function(e) {
  119. if (e.confirm) {
  120. var dtask = plus.downloader.createDownload(
  121. 'https://www.geidcp.com/' + data
  122. .wgt, {},
  123. function(d, status) {
  124. uni.showToast({
  125. title: '下载完成',
  126. mask: false,
  127. duration: 6000
  128. });
  129. // 下载完成
  130. if (status == 200) {
  131. plus.runtime.install(d
  132. .filename, {
  133. force: false
  134. },
  135. function() {
  136. plus.nativeUI
  137. .alert(
  138. "APP更新完成!",
  139. function() {
  140. plus.nativeUI
  141. .closeWaiting();
  142. plus.runtime
  143. .restart();
  144. uni
  145. .hideLoading();
  146. });
  147. console.log(
  148. 'install success...'
  149. );
  150. //plus.runtime.restart();
  151. },
  152. function(e) {
  153. plus.nativeUI
  154. .closeWaiting();
  155. plus.nativeUI
  156. .alert(
  157. "安装更新文件失败[" +
  158. e.code +
  159. "]:" + e
  160. .message);
  161. uni.hideLoading();
  162. console.error(
  163. 'install fail...'
  164. );
  165. });
  166. // console.log('下载成功');
  167. // plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename)
  168. // )
  169. // plus.nativeUI.alert("APP更新完成!",function(){
  170. // plus.runtime.restart();
  171. // });
  172. } else {
  173. uni.showToast({
  174. title: '更新失败-02',
  175. mask: false,
  176. duration: 3500
  177. });
  178. }
  179. });
  180. try {
  181. dtask.start(); // 开启下载的任务
  182. var prg = 0;
  183. var showLoading = plus.nativeUI
  184. .showWaiting(
  185. "正在下载"); //创建一个showWaiting对象
  186. dtask.addEventListener('statechanged',
  187. function(
  188. task,
  189. status
  190. ) {
  191. // 给下载任务设置一个监听 并根据状态 做操作
  192. switch (task.state) {
  193. case 1:
  194. showLoading.setTitle(
  195. "正在下载");
  196. break;
  197. case 2:
  198. showLoading.setTitle(
  199. "已连接到服务器");
  200. break;
  201. case 3:
  202. prg = parseInt(
  203. (parseFloat(
  204. task
  205. .downloadedSize
  206. ) /
  207. (parseFloat(
  208. data
  209. .wgtSize
  210. ) *
  211. 1048576
  212. )) *
  213. 100
  214. );
  215. showLoading.setTitle(
  216. " 正在下载" +
  217. prg + "% ");
  218. break;
  219. case 4:
  220. plus.nativeUI
  221. .closeWaiting();
  222. //下载完成
  223. console.log(
  224. 'task.downloadedSize ' +
  225. task
  226. .downloadedSize
  227. );
  228. console.log(
  229. 'data.wgtSize ' +
  230. data.wgtSize);
  231. break;
  232. }
  233. });
  234. } catch (err) {
  235. plus.nativeUI.closeWaiting();
  236. uni.showToast({
  237. title: '更新失败-03',
  238. mask: false,
  239. duration: 1500
  240. });
  241. }
  242. } else {
  243. //取消
  244. }
  245. }
  246. });
  247. }
  248. },
  249. })
  250. })
  251. // #endif
  252. /* plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  253. console.log('进入热更新访问路径');
  254. let BASE_URL = 'https://www.geidcp.com/api'
  255. uni.request({
  256. url: BASE_URL+'/project/appSoftwares/searchIsNew',
  257. method: 'get',
  258. data:{
  259. //当前版本
  260. currentVersion: widgetInfo.version,
  261. //当前软件名称
  262. softwareName: widgetInfo.name,
  263. //系统类型
  264. softwarePlatformTypeDict:plus.os.name
  265. },
  266. success: (result) => {
  267. console.log('提示一下当前版本'+widgetInfo.version);
  268. var data = result.data.data;
  269. if (data.flag === false) {
  270. console.log('进入热更新');
  271. uni.showModal({
  272. title: '版本更新' ,
  273. content: '发现新版本请问是否进行更新',
  274. success: function(e) {
  275. if (e.confirm) {
  276. if (plus.os.name.toLowerCase() == 'ios'||plus.os.name.toLowerCase() == 'IOS') {
  277. // 跳转到下载页面
  278. plus.runtime.openURL('https://www.geidcp.com/'+data.wgt)
  279. } else {
  280. var dtask = plus.downloader.createDownload(
  281. 'https://www.geidcp.com/'+data.wgt, {},
  282. function(d, status) {
  283. uni.showToast({
  284. title: '下载完成',
  285. mask: false,
  286. duration: 6000
  287. });
  288. // 下载完成
  289. if (status == 200) {
  290. console.log('下载成功');
  291. plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, e => e, function(error) {
  292. uni.showToast({
  293. title: '安装失败-01',
  294. mask: false,
  295. duration: 3500
  296. });
  297. })
  298. plus.nativeUI.alert("APP更新完成!",function(){
  299. plus.runtime.restart();
  300. });
  301. } else {
  302. uni.showToast({
  303. title: '更新失败-02',
  304. mask: false,
  305. duration: 3500
  306. });
  307. }
  308. });
  309. try {
  310. dtask.start(); // 开启下载的任务
  311. var prg = 0;
  312. var showLoading = plus.nativeUI.showWaiting("正在下载"); //创建一个showWaiting对象
  313. dtask.addEventListener('statechanged', function(
  314. task,
  315. status
  316. ) {
  317. // 给下载任务设置一个监听 并根据状态 做操作
  318. switch (task.state) {
  319. case 1:
  320. showLoading.setTitle("正在下载");
  321. break;
  322. case 2:
  323. showLoading.setTitle("已连接到服务器");
  324. break;
  325. case 3:
  326. prg = parseInt(
  327. (parseFloat(task.downloadedSize) /
  328. (parseFloat(data.wgtSize) * 1048576)) *
  329. 100
  330. );
  331. showLoading.setTitle(" 正在下载" + prg + "% ");
  332. break;
  333. case 4:
  334. plus.nativeUI.closeWaiting();
  335. //下载完成
  336. console.log('task.downloadedSize '+task.downloadedSize);
  337. console.log('data.wgtSize '+data.wgtSize);
  338. break;
  339. }
  340. });
  341. } catch (err) {
  342. plus.nativeUI.closeWaiting();
  343. uni.showToast({
  344. title: '更新失败-03',
  345. mask: false,
  346. duration: 1500
  347. });
  348. }
  349. }
  350. } else {
  351. //取消
  352. }
  353. }
  354. });
  355. }
  356. },
  357. })
  358. }) */
  359. /* plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  360. let BASE_URL = 'https://www.geidcp.com/api'
  361. uni.request({
  362. url: BASE_URL+'/project/appSoftwares/searchIsNew',
  363. method: 'get',
  364. data:{
  365. //当前版本
  366. currentVersion: widgetInfo.version,
  367. //当前软件名称
  368. softwareName: widgetInfo.name,
  369. //系统类型
  370. softwarePlatformTypeDict:plus.os.name
  371. },
  372. success: (result) => {
  373. var data = result.data.data;
  374. if (data.flag === false) {
  375. uni.showModal({
  376. title: '发现新版本',
  377. content: '是否进行更新',
  378. success: function (res) {
  379. if (res.confirm) {
  380. uni.showLoading({
  381. title: '更新中...'
  382. })
  383. uni.downloadFile({
  384. url: 'https://www.geidcp.com/'+data.wgt,
  385. success: (downloadResult) => {
  386. if (downloadResult.statusCode === 200) {
  387. plus.runtime.install(downloadResult.tempFilePath, {
  388. force: false
  389. }, function() {
  390. plus.nativeUI.alert("APP更新完成!",function(){
  391. plus.nativeUI.closeWaiting();
  392. plus.runtime.restart();
  393. uni.hideLoading();
  394. });
  395. console.log('install success...');
  396. //plus.runtime.restart();
  397. }, function(e) {
  398. plus.nativeUI.closeWaiting();
  399. plus.nativeUI.alert("安装更新文件失败["+e.code+"]:"+e.message);
  400. uni.hideLoading();
  401. console.error('install fail...');
  402. });
  403. }
  404. }
  405. });
  406. console.log('用户点击确定');
  407. } else if (res.cancel) {
  408. console.log('用户点击取消');
  409. }
  410. }
  411. });
  412. }
  413. }
  414. });
  415. }); */
  416. // #ifdef APP-PLUS
  417. //设置2.4秒后主动关闭,最多设置6秒
  418. // setTimeout(() => {
  419. // plus.navigator.closeSplashscreen();
  420. // }, 3000);
  421. // #endif
  422. },
  423. methods: {
  424. ...mapMutations(['setCartNum', 'setNotifyNum']),
  425. // 数据初始化
  426. async initData() {
  427. uni.setTabBarStyle({
  428. selectedColor: this.themeColor.color,
  429. borderStyle: 'white'
  430. });
  431. this.themeColor.tabList && this.themeColor.tabList.forEach((selectedIconPath, index) => {
  432. uni.setTabBarItem({
  433. index,
  434. selectedIconPath
  435. });
  436. });
  437. if (this.$i18n.locale == 'zh') {
  438. document.title = _self.AgentSystemSet.WebSiteName;
  439. debugger
  440. } else {
  441. }
  442. // 获取页面设置配置
  443. const token = uni.getStorageSync('accessToken');
  444. // 获取系统title高度
  445. await this.initSystemInfo();
  446. if (token) {
  447. await this.handleVerifyAccessToken(token);
  448. }
  449. if (this.$mStore.getters.hasLogin) {
  450. this.setCartNum(uni.getStorageSync('cartNum') || 0);
  451. this.setNotifyNum(uni.getStorageSync('notifyNum') || 0);
  452. // #ifdef APP-PLUS
  453. const info = plus.push.getClientInfo();
  454. // #endif
  455. }
  456. // #ifdef H5
  457. if (this.$mPayment.isWechat()) {
  458. await this.$mPayment.wxConfigH5(window.location.href);
  459. }
  460. // #endif
  461. },
  462. // 初始化系统信息
  463. initSystemInfo() {
  464. uni.getSystemInfo({
  465. success(e) {
  466. // #ifndef MP
  467. Vue.prototype.StatusBar = e.statusBarHeight;
  468. if (e.platform === 'android') {
  469. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  470. } else {
  471. Vue.prototype.CustomBar = e.statusBarHeight + 43;
  472. }
  473. // #endif
  474. // #ifdef MP-WEIXIN
  475. Vue.prototype.StatusBar = e.statusBarHeight;
  476. // eslint-disable-next-line
  477. const custom = wx.getMenuButtonBoundingClientRect();
  478. Vue.prototype.Custom = custom;
  479. Vue.prototype.CustomBar = custom.top - e.statusBarHeight;
  480. // #endif
  481. // #ifdef MP-ALIPAY
  482. Vue.prototype.StatusBar = e.statusBarHeight;
  483. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  484. // #endif
  485. }
  486. });
  487. },
  488. // 检验token是否有效
  489. async handleVerifyAccessToken(token) {
  490. await this.$http.post(verifyAccessToken, {
  491. token
  492. }).then(r => {
  493. if (!r.data.token) {
  494. this.$mStore.commit('logout');
  495. }
  496. });
  497. }
  498. }
  499. };
  500. </script>
  501. <style lang="scss">
  502. /* #ifndef APP-PLUS-NVUE
  503. @import "uview-ui/index.scss";
  504. // 导入colorUI
  505. @import '/static/css/colorui/main.css';
  506. @import '/static/css/colorui/icon.css';
  507. @import '/static/css/colorui/animation.css';
  508. @import './static/css/iconfont/iconfont.css';
  509. @import './static/css/reset.scss';
  510. @import './static/css/uni.scss';
  511. @import './static/css/font-awesome/css/font-awesome.css';
  512. /* #endif */
  513. uni-page-head {
  514. display: none;
  515. }
  516. // 导入阿里巴巴矢量图标库
  517. /*#ifdef MP*/
  518. @import './static/css/iconfont/iconfont.css';
  519. /*#endif*/
  520. /*#ifndef MP || APP-PLUS-NVUE*/
  521. @import url('https://at.alicdn.com/t/font_1681579_dwilkcq6mvg.css');
  522. /*#endif*/
  523. </style>