SwitchWindow.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div>
  3. <div class="switchWindow" :class="switchActive === true ? 'on' : ''">
  4. <!-- @assets/images/public.png -->
  5. <div class="pictrue">
  6. <img v-if="login_type === 'h5'" src="@assets/images/h5.png" />
  7. <img src="@assets/images/h5.png" alt="" v-else />
  8. </div>
  9. <!-- 是否选择切换到小程序账户? -->
  10. <div class="info">
  11. 是否选择切换到<span class="font-color" v-if="login_type === 'h5'"
  12. >微信账号</span
  13. >
  14. <span class="font-color" v-else>手机用户</span>?
  15. </div>
  16. <div class="switchBnt" @click="switchH5">切换</div>
  17. <div class="switchBnt cancelBnt" @click="switchClose">取消</div>
  18. </div>
  19. <div
  20. class="mask"
  21. @touchmove.prevent
  22. v-show="switchActive === true"
  23. @click="switchClose"
  24. ></div>
  25. </div>
  26. </template>
  27. <style>
  28. .switchWindow {
  29. width: 5.6rem;
  30. border-radius: 0.2rem;
  31. -webkit-border-radius: 0.2rem;
  32. background-color: #fff;
  33. position: fixed;
  34. top: 50%;
  35. left: 50%;
  36. margin-left: -2.8rem;
  37. margin-top: -3rem;
  38. z-index: 99;
  39. padding: 0.5rem 0.3rem 0.4rem 0.3rem;
  40. text-align: center;
  41. box-sizing: border-box;
  42. -webkit-box-sizing: border-box;
  43. transition: all 0.3s ease-in-out 0s;
  44. -webkit-transition: all 0.3s ease-in-out 0s;
  45. -moz-transition: all 0.3s ease-in-out 0s;
  46. -o-transition: all 0.3s ease-in-out 0s;
  47. opacity: 0;
  48. transform: scale(0);
  49. }
  50. .switchWindow.on {
  51. opacity: 1;
  52. transform: scale(1);
  53. -webkit-transform: scale(1);
  54. -ms-transform: scale(1);
  55. -moz-transform: scale(1);
  56. -o-transform: scale(1);
  57. }
  58. .switchWindow .pictrue {
  59. width: 2.36rem;
  60. height: 2.36rem;
  61. margin: 0 auto;
  62. }
  63. .switchWindow .pictrue img {
  64. width: 100%;
  65. height: 100%;
  66. display: block;
  67. }
  68. .switchWindow .info {
  69. font-size: 0.32rem;
  70. color: #282828;
  71. margin-top: 0.44rem;
  72. font-weight: bold;
  73. }
  74. .switchWindow .switchBnt {
  75. font-size: 0.32rem;
  76. color: #fff;
  77. width: 3.6rem;
  78. height: 0.82rem;
  79. border-radius: 0.41rem;
  80. -webkit-border-radius: 0.41rem;
  81. margin: 0.57rem auto 0 auto;
  82. line-height: 0.82rem;
  83. background-image: linear-gradient(to right, #f67a38 0%, #f11b09 100%);
  84. background-image: -webkit-linear-gradient(to right, #f67a38 0%, #f11b09 100%);
  85. background-image: -moz-linear-gradient(to right, #f67a38 0%, #f11b09 100%);
  86. }
  87. .switchWindow .switchBnt.cancelBnt {
  88. background-color: #fff;
  89. color: #999;
  90. background-image: none;
  91. margin-top: 0.1rem;
  92. }
  93. </style>
  94. <script>
  95. import { clearAuthStatus } from "@libs/wechat";
  96. import { switchH5Login } from "@api/user";
  97. import cookie from "@utils/store/cookie";
  98. import store from "@/store";
  99. import dayjs from "dayjs";
  100. export default {
  101. name: "SwitchWindow",
  102. props: {
  103. switchActive: {
  104. type: Boolean,
  105. default: false
  106. },
  107. login_type: {
  108. type: String,
  109. default: ""
  110. }
  111. },
  112. data: function() {
  113. return {};
  114. },
  115. mounted: function() {},
  116. methods: {
  117. switchClose: function() {
  118. this.$emit("changeswitch", false); //$emit():注册事件;
  119. },
  120. switchH5() {
  121. let that = this;
  122. this.$dialog.loading.open("正在切换中");
  123. if (that.login_type === "h5") {
  124. cookie.set("loginType", "wechat", 60);
  125. this.$dialog.loading.close();
  126. this.$store.commit("LOGOUT");
  127. clearAuthStatus();
  128. this.$emit("changeswitch", false);
  129. location.reload();
  130. } else {
  131. switchH5Login()
  132. .then(({ data }) => {
  133. this.$dialog.loading.close();
  134. const expires_time = dayjs(data.expires_time);
  135. store.commit("LOGIN", data.token, expires_time);
  136. this.$emit("changeswitch", false);
  137. location.reload();
  138. })
  139. .catch(err => {
  140. this.$dialog.loading.close();
  141. return that.$dialog.toast({ mes: err });
  142. });
  143. }
  144. }
  145. }
  146. };
  147. </script>