You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.vue 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <script>
  2. import {
  3. request,requestNew
  4. } from "@/utils/network/request.js";
  5. import {
  6. getGlobalParam,
  7. wechatAppID,
  8. wechatSecret,
  9. getZfbOpenid,getOpenId
  10. } from "@/utils/network/api.js";
  11. import {
  12. msg
  13. } from "./utils/utils";
  14. import {
  15. getItem,
  16. setItem
  17. } from "./utils/storage";
  18. import {
  19. stringToJson
  20. } from "@/utils/network/encryption";
  21. import {
  22. getCodeName
  23. } from "@/datas/queryKey.js";
  24. export default {
  25. onLaunch: function(option) {
  26. var that = this;
  27. uni.getSystemInfo({
  28. success: (res) => {
  29. if (res.uniPlatform === 'mp-weixin') {
  30. setItem("loginSource", "69af303ba2eb4608a099163f0d2a5dbd");
  31. setItem("environment", "WX")
  32. } else if (res.uniPlatform === 'mp-alipay') {
  33. setItem("loginSource", "601052a249c04155831710b577cb796d");
  34. setItem("environment", "ZFB")
  35. }
  36. that.globalParam();
  37. }
  38. });
  39. //获取微信小程序openid
  40. // #ifdef MP-WEIXIN
  41. uni.login({
  42. provider: "weixin",
  43. success: function(e) {
  44. console.log("jsCode",e.code)
  45. that.getOpenid(e.code);
  46. },
  47. });
  48. // #endif
  49. // #ifdef MP-ALIPAY
  50. my.getAuthCode({
  51. scopes: 'auth_base',
  52. success: res => {
  53. console.log("支付宝授权码", res.authCode)
  54. const options = {
  55. type: 2,
  56. data: {
  57. "code": res.authCode
  58. },
  59. method: "POST",
  60. };
  61. requestNew(getZfbOpenid, options).then((res) => {
  62. const result = res;
  63. console.log("getZfbOpenid",getZfbOpenid)
  64. if (result.openId) {
  65. setItem("zfbOpenId", result.openId);
  66. } else {
  67. setItem("zfbUserId", result.userId);
  68. }
  69. });
  70. },
  71. });
  72. // #endif
  73. uni.setStorageSync("extraData", option.referrerInfo.extraData);
  74. // #ifdef MP-WEIXIN
  75. //获取小程序更新机制兼容
  76. if (uni.canIUse("getUpdateManager")) {
  77. // pdateManager,用于管理小程序更新。
  78. const updateManager = uni.getUpdateManager();
  79. updateManager.onCheckForUpdate(function(res) {
  80. // 请求完新版本信息的回调
  81. if (res.hasUpdate) {
  82. updateManager.onUpdateReady(function() {
  83. uni.showModal({
  84. title: "更新提示",
  85. content: "新版本已经准备好,是否重启应用?",
  86. success: function(res) {
  87. if (res.confirm) {
  88. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  89. updateManager.applyUpdate();
  90. }
  91. },
  92. });
  93. });
  94. updateManager.onUpdateFailed(function() {
  95. // 新的版本下载失败
  96. uni.showModal({
  97. title: "已经有新版本了哟~",
  98. content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~",
  99. showCancel: false,
  100. confirmText: "我知道了",
  101. });
  102. });
  103. }
  104. });
  105. } else {
  106. // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
  107. uni.showModal({
  108. title: "提示",
  109. content: "当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。",
  110. showCancel: false,
  111. confirmText: "我知道了",
  112. });
  113. }
  114. // #endif
  115. },
  116. onShow: function(option) {
  117. console.log("进入主视图");
  118. },
  119. onLoad: function(option) {
  120. },
  121. onHide: function() {},
  122. methods: {
  123. globalParam() {
  124. const options = {
  125. type: 2,
  126. data: {
  127. "loginSource": getItem("loginSource")
  128. },
  129. method: "POST",
  130. showLoading: true,
  131. };
  132. requestNew(getGlobalParam, options).then((res) => {
  133. const result = stringToJson(res.bizContent);
  134. setItem('globalParam', result.data)
  135. });
  136. },
  137. getOpenid(code) {
  138. const options = {
  139. type: 2,
  140. data: {
  141. "jsCode": code
  142. },
  143. method: "POST",
  144. };
  145. // #ifdef MP-WEIXIN
  146. requestNew(getOpenId, options).then((res) => {
  147. const result =res;
  148. console.log("getOpenId===",result)
  149. const openidData = stringToJson(result.data);
  150. console.log("openidData====",openidData)
  151. setItem("QYorder", openidData);
  152. });
  153. // #endif
  154. },
  155. }
  156. };
  157. </script>
  158. <style lang="scss">
  159. /*每个页面公共css */
  160. @import "./static/css/common.scss";
  161. page {
  162. font-family: "Microsoft Yahei";
  163. background-color: #E9EDF0;
  164. font-size: 32rpx;
  165. }
  166. </style>