wangCg.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="login-overlay" v-if="loginStyle == 0">
  3. <view class="login-modal">
  4. <!-- 背景装饰 -->
  5. <view class="bg-decoration">
  6. <view class="circle circle-1"></view>
  7. <view class="circle circle-2"></view>
  8. </view>
  9. <!-- 主要内容 -->
  10. <view class="content-wrapper">
  11. <!-- 图标区域 -->
  12. <view class="icon-section">
  13. <view class="login-icon">
  14. <text class="icon-text">🔐</text>
  15. </view>
  16. </view>
  17. <!-- 文字区域 -->
  18. <view class="text-section">
  19. <view class="title">请先登录</view>
  20. <view class="subtitle">登录后享受更多功能</view>
  21. </view>
  22. <!-- 按钮区域 -->
  23. <view class="button-section">
  24. <button class="login-btn" open-type="getPhoneNumber" @getphonenumber="getWxMobile">
  25. <text class="btn-text">手机号一键登录</text>
  26. </button>
  27. </view>
  28. <!-- 说明文字 -->
  29. <view class="notice-section">
  30. <text class="notice-text">为了更好提供服务,需要获取您的手机号,如不接受,你可以拒绝使用,点右上角关闭此小程序</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { getWxPhone } from "@/api/mini"
  38. import { create } from "@/api/user"
  39. import store from '@/store'
  40. export default {
  41. props: {
  42. loginStyle: {
  43. type: Number,
  44. default: 0,
  45. }
  46. },
  47. data() {
  48. return {
  49. form: {
  50. mobile: ""
  51. }
  52. };
  53. },
  54. methods: {
  55. getWxMobile(e) {
  56. let that = this
  57. if (e.detail.errMsg === "getPhoneNumber:ok") {
  58. let currentMiniOpenId = uni.getStorageSync('miniOpenId')
  59. getWxPhone({ iv: e.detail.iv, encryptedData: e.detail.encryptedData, miniOpenId: currentMiniOpenId }).then(subRes => {
  60. if(subRes.data && subRes.data.hasNoOpenId && subRes.data.hasNoOpenId == 1){
  61. uni.showModal({
  62. title: '提示',
  63. content: '网络异常,请重试一次',
  64. success: function (res) {
  65. if (res.confirm) {
  66. console.log('用户点击确定')
  67. }
  68. }
  69. })
  70. return false
  71. }
  72. this.form.mobile = subRes.data.mobile
  73. that.confirmFn()
  74. })
  75. } else {
  76. this.$msg("获取手机失败");
  77. }
  78. },
  79. confirmFn() {
  80. let currentMiniOpenId = uni.getStorageSync('miniOpenId')
  81. let that = this
  82. create({miniOpenId: currentMiniOpenId, ...this.form}).then(res => {
  83. if(res.code == 1){
  84. uni.setStorageSync('token', res.data.token)
  85. if(res.data.user && !that.$util.isEmpty(res.data.user)){
  86. store.commit('setLoginInfo', res.data.user)
  87. that.$msg('登录成功')
  88. // 登录成功后触发事件通知父组件
  89. this.$emit('loginSuccess', res.data.user)
  90. }
  91. }
  92. })
  93. }
  94. },
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. .login-overlay {
  99. position: fixed;
  100. z-index: 9999;
  101. top: 0;
  102. left: 0;
  103. width: 100vw;
  104. height: 100vh;
  105. background: rgba(0, 0, 0, 0.6);
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. }
  110. .login-modal {
  111. position: relative;
  112. width: 550upx;
  113. max-width: 95vw;
  114. background: #ffffff;
  115. border-radius: 24upx;
  116. box-shadow: 0 20upx 60upx rgba(0, 0, 0, 0.3);
  117. overflow: hidden;
  118. animation: modalShow 0.3s ease-out;
  119. }
  120. @keyframes modalShow {
  121. from {
  122. opacity: 0;
  123. transform: scale(0.8) translateY(50upx);
  124. }
  125. to {
  126. opacity: 1;
  127. transform: scale(1) translateY(0);
  128. }
  129. }
  130. // 背景装饰
  131. .bg-decoration {
  132. position: absolute;
  133. top: 0;
  134. left: 0;
  135. width: 100%;
  136. height: 100%;
  137. overflow: hidden;
  138. .circle {
  139. position: absolute;
  140. border-radius: 50%;
  141. background: rgba(0, 0, 0, 0.05);
  142. animation: float 4s ease-in-out infinite;
  143. &.circle-1 {
  144. width: 80upx;
  145. height: 80upx;
  146. top: 20%;
  147. right: 10%;
  148. animation-delay: 0s;
  149. }
  150. &.circle-2 {
  151. width: 60upx;
  152. height: 60upx;
  153. bottom: 30%;
  154. left: 10%;
  155. animation-delay: 2s;
  156. }
  157. }
  158. }
  159. @keyframes float {
  160. 0%, 100% {
  161. transform: translateY(0px) rotate(0deg);
  162. }
  163. 50% {
  164. transform: translateY(-10px) rotate(90deg);
  165. }
  166. }
  167. .content-wrapper {
  168. position: relative;
  169. z-index: 2;
  170. text-align: center;
  171. padding: 60upx 40upx;
  172. }
  173. // 图标区域
  174. .icon-section {
  175. margin-bottom: 40upx;
  176. .login-icon {
  177. width: 100upx;
  178. height: 100upx;
  179. margin: 0 auto;
  180. background: rgba(0, 0, 0, 0.05);
  181. border-radius: 50%;
  182. display: flex;
  183. align-items: center;
  184. justify-content: center;
  185. backdrop-filter: blur(10px);
  186. border: 2upx solid rgba(0, 0, 0, 0.1);
  187. box-shadow: 0 8upx 32upx rgba(0, 0, 0, 0.1);
  188. .icon-text {
  189. font-size: 70upx;
  190. }
  191. }
  192. }
  193. // 文字区域
  194. .text-section {
  195. margin-bottom: 50upx;
  196. .title {
  197. font-size: 50upx;
  198. font-weight: 600;
  199. color: #333333;
  200. margin-bottom: 16upx;
  201. text-shadow: none;
  202. }
  203. .subtitle {
  204. font-size: 36upx;
  205. color: #666666;
  206. line-height: 1.4;
  207. text-shadow: none;
  208. }
  209. }
  210. // 按钮区域
  211. .button-section {
  212. margin-bottom: 30upx;
  213. .login-btn {
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. width: 100%;
  218. height: 88upx;
  219. background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  220. border-radius: 44upx;
  221. box-shadow: 0 8upx 24upx rgba(238, 90, 36, 0.4);
  222. transition: all 0.3s ease;
  223. border: none;
  224. cursor: pointer;
  225. padding: 0;
  226. margin: 0;
  227. &:active {
  228. transform: translateY(2upx);
  229. box-shadow: 0 4upx 12upx rgba(238, 90, 36, 0.4);
  230. }
  231. &::after {
  232. border: none;
  233. }
  234. .btn-icon {
  235. font-size: 32upx;
  236. margin-right: 12upx;
  237. }
  238. .btn-text {
  239. font-size: 40upx;
  240. font-weight: 600;
  241. color: #ffffff;
  242. letter-spacing: 1upx;
  243. }
  244. }
  245. }
  246. // 说明文字区域
  247. .notice-section {
  248. .notice-text {
  249. font-size: 28upx;
  250. color: #999999;
  251. line-height: 1.5;
  252. text-align: center;
  253. text-shadow: none;
  254. }
  255. }
  256. // 响应式适配
  257. @media (max-width: 750upx) {
  258. .login-modal {
  259. width: 580upx;
  260. }
  261. .content-wrapper {
  262. padding: 50upx 30upx;
  263. }
  264. .icon-section .login-icon {
  265. width: 80upx;
  266. height: 80upx;
  267. .icon-text {
  268. font-size: 56upx;
  269. }
  270. }
  271. .text-section .title {
  272. font-size: 42upx;
  273. }
  274. .text-section .subtitle {
  275. font-size: 34upx;
  276. }
  277. .button-section .login-btn {
  278. height: 80upx;
  279. .btn-text {
  280. font-size: 38upx;
  281. }
  282. }
  283. }
  284. </style>