App.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <script>
  2. import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
  3. import {login} from "@/api/member";
  4. import tools from "@/common/js/tools";
  5. export default {
  6. onLaunch: function () {
  7. console.log("App Launch");
  8. let bnbObj= tokenpocketBnb.getProvider()
  9. bnbObj.on('accountsChanged',(accounts)=>{
  10. if(accounts.length<=0){
  11. uni.reLaunch({
  12. 'url':'pages/index/error?errorType=2'
  13. })
  14. }else {
  15. uni.setStorageSync('babAddress',accounts[0])
  16. uni.setStorageSync('token', '');
  17. this.login(accounts[0])
  18. }
  19. })
  20. bnbObj.on('chainChanged',(chainId)=>{
  21. if(chainId!=='0x38'){
  22. uni.reLaunch({
  23. 'url':'pages/index/error?errorType=5'
  24. })
  25. }else {
  26. uni.reLaunch({
  27. 'url':'pages/index/index'
  28. })
  29. }
  30. })
  31. uni.$on('noBan',()=>{
  32. console.log(this.$Route)
  33. if(this.$Route.path!=='/pages/index/error'){
  34. uni.reLaunch({
  35. 'url':'pages/index/error?errorType=5'
  36. })
  37. }
  38. })
  39. },
  40. onShow: function () {
  41. console.log("App Show");
  42. },
  43. onHide: function () {
  44. console.log("App Hide");
  45. },
  46. methods:{
  47. login(Address){
  48. login({'address':Address}).then((res)=>{
  49. if(res.code===1){
  50. tools.setLoginInfo(res.data)
  51. setTimeout(()=>{
  52. uni.reLaunch({
  53. url: '/pages/index/index'
  54. })
  55. },50)
  56. }else {
  57. uni.reLaunch({
  58. url: 'pages/login/register?address='+Address
  59. })
  60. }
  61. })
  62. }
  63. }
  64. };
  65. </script>
  66. <style>
  67. /*每个页面公共css */
  68. @import "./common/css/common";
  69. /* icon */
  70. @import "./common/font/iconfont";
  71. checkbox .wx-checkbox-input {
  72. border-radius: 50% !important;
  73. }
  74. checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  75. background: linear-gradient(129deg, #f0695b 0%, #ed301d 100%);
  76. border: 1px solid rgb(239, 74, 57);
  77. box-shadow: 0px 2px 3px rgba(239, 74, 57, 0.16);
  78. }
  79. uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
  80. border-color: #d1d1d1;
  81. }
  82. </style>