index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="app-page">
  3. <u-loading-icon text="加载中" textSize="18" :vertical="true"></u-loading-icon>
  4. <u-no-network @disconnected="disconnected" @connected="connected" @retry="retry"></u-no-network>
  5. </view>
  6. </template>
  7. <script>
  8. import {
  9. userLogin
  10. } from "@/common/api/user.js";
  11. import {
  12. bindFrom
  13. } from "@/common/api/common.js";
  14. export default {
  15. data() {
  16. return {
  17. from: null,
  18. goodCode: null,
  19. }
  20. },
  21. onLoad(options) {
  22. console.log('options=>', options);
  23. if (options.id) {
  24. this.from = options.id;
  25. }
  26. if (options.code) {
  27. this.goodCode = options.code;
  28. }
  29. this.getWxCode();
  30. // uni.reLaunch({
  31. // url: '/pages/afterSales/afterSales'
  32. // // url: "/pages/home/index"
  33. // })
  34. // if (!options.id && !options.code) {
  35. // setTimeout(() => {
  36. // uni.reLaunch({
  37. // url: "/pages/home/index"
  38. // })
  39. // }, 10);
  40. // } else {
  41. // // && uni.getStorageSync('token')
  42. // this.getWxCode();
  43. // }
  44. },
  45. methods: {
  46. disconnected() {
  47. console.log('disconnected');
  48. },
  49. connected() {
  50. console.log('connected');
  51. // this.getWxCode();
  52. },
  53. retry() {
  54. console.log('retry');
  55. },
  56. getWxCode() {
  57. const that = this;
  58. uni.login({
  59. provider: "weixin",
  60. success: (wxRes) => {
  61. console.log("wxCode==>", wxRes.code)
  62. uni.showToast({
  63. title: 'wxlogin'
  64. })
  65. that.userLogin(wxRes.code);
  66. },
  67. fail: (err) => {
  68. uni.showToast({
  69. title: err
  70. })
  71. }
  72. })
  73. },
  74. userLogin(code) {
  75. const data = {
  76. code: code
  77. };
  78. userLogin(data)
  79. .then((res) => {
  80. console.log("userLogin==>", res.data)
  81. console.log("userLogin==>", res.data.token.token)
  82. uni.showToast({
  83. title: 'userLogin'
  84. })
  85. if (res.data) {
  86. uni.setStorageSync('token', res.data.token.token)
  87. uni.showToast({
  88. title: 'successserLogin'
  89. })
  90. const userInfo = uni.getStorageSync('userInfo') || '{}';
  91. console.log(89999, userInfo, JSON.parse(userInfo).username)
  92. if (userInfo && !JSON.parse(userInfo).username) {} else {
  93. uni.setStorageSync('userInfo', JSON.stringify(res.data))
  94. }
  95. console.log(8888, this.from)
  96. if (this.from) {
  97. if (this.from === JSON.parse(userInfo).id) {
  98. if (this.goodCode) {
  99. uni.reLaunch({
  100. url: '/pages/home/index?code=' + this.goodCode
  101. })
  102. } else {
  103. uni.reLaunch({
  104. url: "/pages/home/index"
  105. })
  106. }
  107. return
  108. }
  109. this.bindFrom()
  110. } else {
  111. if (this.goodCode) {
  112. uni.reLaunch({
  113. url: '/pages/home/index?code=' + this.goodCode
  114. })
  115. } else {
  116. // uni.showToast({
  117. // title: '5'
  118. // })
  119. uni.reLaunch({
  120. url: "/pages/home/index",
  121. })
  122. }
  123. }
  124. }
  125. }).catch((err) => {
  126. // uni.showToast({
  127. // title: '6'
  128. // })
  129. })
  130. },
  131. bindFrom(code) {
  132. const data = {
  133. puid: this.from
  134. };
  135. bindFrom(data)
  136. .then((res) => {
  137. console.log("bindFrom==>", res.data)
  138. if (res.data) {
  139. if (this.goodCode) {
  140. uni.reLaunch({
  141. url: '/pages/home/index?code=' + this.goodCode
  142. })
  143. } else {
  144. uni.reLaunch({
  145. url: "/pages/home/index"
  146. // url: '/pages/privateSphere/index'
  147. })
  148. }
  149. } else {
  150. if (this.goodCode) {
  151. uni.reLaunch({
  152. url: '/pages/home/index?code=' + this.goodCode
  153. })
  154. } else {
  155. uni.reLaunch({
  156. url: "/pages/home/index"
  157. // url: '/pages/privateSphere/index'
  158. })
  159. }
  160. }
  161. })
  162. .catch(() => {
  163. uni.hideLoading();
  164. if (this.goodCode) {
  165. uni.reLaunch({
  166. url: '/pages/home/index?code=' + this.goodCode
  167. })
  168. } else {
  169. uni.reLaunch({
  170. url: "/pages/home/index"
  171. // url: '/pages/privateSphere/index'
  172. })
  173. }
  174. });
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .app-page {
  181. width: 100%;
  182. justify-content: center;
  183. height: 100vh;
  184. display: flex;
  185. background: transparent;
  186. align-items: center;
  187. flex-direction: column;
  188. }
  189. .u-content {
  190. padding: 150px 60px 0;
  191. @include flex(column);
  192. align-items: center;
  193. justify-content: center;
  194. &__circle {
  195. background-color: $u-success;
  196. @include flex;
  197. border-radius: 100px;
  198. width: 60px;
  199. height: 60px;
  200. align-items: center;
  201. justify-content: center;
  202. }
  203. &__normal {
  204. font-size: 15px;
  205. color: $u-success;
  206. margin-top: 15px;
  207. }
  208. }
  209. </style>