时空网前端
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.

194 lines
6.0 KiB

  1. <script>
  2. export default {
  3. globalData: {
  4. wxlogin: () => {}
  5. },
  6. onLaunch: function() {
  7. this.getUserInfo();
  8. },
  9. onShow: function() {
  10. // #ifdef MP-WEIXIN
  11. this.getUpdateWexin(); // 小程序更新检查
  12. // #endif
  13. },
  14. onHide: function() {
  15. console.log('App Hide')
  16. },
  17. methods: {
  18. wxlogin(){
  19. uni.login({
  20. complete: result => {
  21. if(result.errMsg == 'login:ok'){
  22. let code = result.code;
  23. this.$http(this.API.API_WXLOGIN, { code }).then(res => {
  24. console.log("获得用户信息", res);
  25. uni.setStorageSync('userinfo', res.data);
  26. })
  27. }
  28. }
  29. })
  30. },
  31. // 获取用户信息
  32. getUserInfo(){
  33. this.globalData.wxlogin = this.wxlogin;
  34. let userinfo = uni.getStorageSync('userinfo');
  35. if(userinfo && userinfo.id){
  36. return;
  37. }
  38. // console.log(this.globalData)
  39. this.wxlogin();
  40. // uni.login({
  41. // complete: result => {
  42. // if(result.errMsg == 'login:ok'){
  43. // let code = result.code;
  44. // this.userCode(code);
  45. // }
  46. // }
  47. // })
  48. },
  49. // 接口code换取用户信息
  50. userCode(code){
  51. console.log("code", code);
  52. this.$http(this.API.API_WXLOGIN, { code }).then(res => {
  53. console.log("获得用户信息", res);
  54. uni.setStorageSync('userinfo', res.data);
  55. })
  56. },
  57. // 登录
  58. login(){
  59. this.checkSession().then(code => {
  60. this.userCode(code);
  61. }).catch(err => {
  62. console.log("进入。。。。。。")
  63. uni.login({
  64. complete: result => {
  65. console.log(result)
  66. if(result.errMsg == 'login:ok'){
  67. let code = result.code;
  68. this.userCode(code);
  69. }
  70. }
  71. })
  72. });
  73. },
  74. // 校验登录态是否过期,如果没有过期还要判断本地有没有token
  75. checkSession(){
  76. return new Promise((resolve, reject) => {
  77. uni.checkSession({
  78. complete: result => {
  79. if(result.errMsg == 'checkSession:ok'){ // 处于登录状态 session未过期
  80. // let login_token = uni.getStorageSync('login_token');
  81. let login_token = undefined;
  82. if(login_token){
  83. resolve(login_token);
  84. }else{
  85. reject(); // 本地没有token,重新调取登录
  86. }
  87. }else{ // session已过期,需要重新登录
  88. reject();
  89. }
  90. }
  91. })
  92. });
  93. },
  94. // 小程序版本更新检查
  95. getUpdateWexin(){
  96. const updateManager = uni.getUpdateManager(); // 获取版本更新管理器对象
  97. updateManager.onCheckForUpdate(function(res) {
  98. // 请求完新版本信息的回调
  99. if (res.hasUpdate) {
  100. updateManager.onUpdateReady(function(res2) {
  101. uni.showModal({
  102. title: '更新提示',
  103. content: '发现新版本,是否重启应用?',
  104. confirmColor: '#FE9903',
  105. showCancel: false,
  106. success(res2) {
  107. if (res2.confirm) {
  108. // 新的版本已经下载好,调用applyUpdate应用新版本并重启
  109. updateManager.applyUpdate();
  110. }
  111. }
  112. });
  113. });
  114. }
  115. });
  116. updateManager.onUpdateFailed(function(res) {
  117. // 新的版本下载失败
  118. uni.showModal({
  119. title: '提示',
  120. content: '检查到有新版本,但下载失败,请检查网络设置',
  121. confirmColor: '#FE9903',
  122. success(res) {
  123. if (res.confirm) {
  124. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  125. updateManager.applyUpdate();
  126. }
  127. }
  128. });
  129. });
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. @import "uview-ui/index.scss";
  136. @import './colorui/main.css';
  137. @import './colorui/icon.css';
  138. @import "@/colorui/animation.css";
  139. @import '@/common/styles/common.css';
  140. /*每个页面公共css */
  141. //底部按钮
  142. .btn-bottom {
  143. position: fixed;
  144. left: 0;
  145. bottom: 0;
  146. width: 100%;
  147. z-index: 1;
  148. }
  149. // loading加载
  150. .loading-more {
  151. align-items: center;
  152. justify-content: center;
  153. padding-top: 10px;
  154. padding-bottom: 10px;
  155. text-align: center;
  156. font-size: 28rpx;
  157. color: #999;
  158. }
  159. .loading-more-text::before {
  160. content: '';
  161. width: 20px;
  162. height: 20px;
  163. display: inline-block;
  164. vertical-align: middle;
  165. -webkit-animation: weuiLoading 1s steps(12, end) infinite;
  166. animation: weuiLoading 1s steps(12, end) infinite;
  167. background-repeat: no-repeat;
  168. background-image: url("data:image/svg+xml;charset=utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 100 100'%3E%3Cpath fill='none' d='M0 0h100v100H0z'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E9E9E9' rx='5' ry='5' transform='translate(0 -30)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23989697' rx='5' ry='5' transform='rotate(30 105.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%239B999A' rx='5' ry='5' transform='rotate(60 75.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23A3A1A2' rx='5' ry='5' transform='rotate(90 65 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23ABA9AA' rx='5' ry='5' transform='rotate(120 58.66 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23B2B2B2' rx='5' ry='5' transform='rotate(150 54.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23BAB8B9' rx='5' ry='5' transform='rotate(180 50 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23C2C0C1' rx='5' ry='5' transform='rotate(-150 45.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23CBCBCB' rx='5' ry='5' transform='rotate(-120 41.34 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23D2D2D2' rx='5' ry='5' transform='rotate(-90 35 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23DADADA' rx='5' ry='5' transform='rotate(-60 24.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E2E2E2' rx='5' ry='5' transform='rotate(-30 -5.98 65)'/%3E%3C/svg%3E");
  169. background-size: 100%;
  170. }
  171. @-webkit-keyframes weuiLoading {
  172. 0% {
  173. transform: rotate3d(0, 0, 1, 0deg);
  174. }
  175. 100% {
  176. transform: rotate3d(0, 0, 1, 360deg);
  177. }
  178. }
  179. @keyframes weuiLoading {
  180. 0% {
  181. transform: rotate3d(0, 0, 1, 0deg);
  182. }
  183. 100% {
  184. transform: rotate3d(0, 0, 1, 360deg);
  185. }
  186. }
  187. </style>