Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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