SwitchWindow.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. export default {
  100. name: "SwitchWindow",
  101. props: {
  102. switchActive: {
  103. type: Boolean,
  104. default: false
  105. },
  106. login_type: {
  107. type: String,
  108. default: ""
  109. }
  110. },
  111. data: function() {
  112. return {};
  113. },
  114. mounted: function() {},
  115. methods: {
  116. switchClose: function() {
  117. this.$emit("changeswitch", false); //$emit():注册事件;
  118. },
  119. switchH5() {
  120. let that = this;
  121. this.$dialog.loading.open("正在切换中");
  122. if (that.login_type === "h5") {
  123. cookie.set("loginType", "wechat", 60);
  124. this.$dialog.loading.close();
  125. this.$store.commit("LOGOUT");
  126. clearAuthStatus();
  127. this.$emit("changeswitch", false);
  128. location.reload();
  129. } else {
  130. switchH5Login()
  131. .then(({ data }) => {
  132. this.$dialog.loading.close();
  133. let expires_time = data.expires_time.substring(0, 19);
  134. expires_time = expires_time.replace(/-/g, "/");
  135. expires_time = new Date(expires_time).getTime() - 28800000;
  136. const datas = {
  137. token: data.token,
  138. expires_time: expires_time
  139. };
  140. store.commit("LOGIN", datas);
  141. this.$emit("changeswitch", false);
  142. location.reload();
  143. })
  144. .catch(err => {
  145. this.$dialog.loading.close();
  146. return that.$dialog.toast({ mes: err });
  147. });
  148. }
  149. }
  150. }
  151. };
  152. </script>