login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="hc-login-box relative h-full p-4">
  3. <view class="hc-dot-box">
  4. <view un-absolute un-b-rounded-100 class="dot dot-1"/>
  5. <view un-absolute un-b-rounded-100 class="dot dot-2"/>
  6. <view un-absolute un-b-rounded-100 class="dot dot-3"/>
  7. </view>
  8. <web-view name="animationIframe" src="/hybrid/html/animation/index.html" :webview-styles="webStyle" :style="webStyle" @message="handleMessage"/>
  9. <view class="hc-login-container">
  10. <view class="hc-login-center">
  11. <view class="hc-login-title">欢迎登录</view>
  12. <view class="hc-login-text">泓创让每一个数据更具价值</view>
  13. <view class="hc-login-form">
  14. <view class="hc-login-form-item">
  15. <input class="hc-login-input" v-model="formData.username" placeholder="请输入登录账户"/>
  16. </view>
  17. <view class="hc-login-form-item">
  18. <input type="password" class="hc-login-input" v-model="formData.password"
  19. placeholder="请输入登录密码"/>
  20. </view>
  21. </view>
  22. <button class="mt-16" :type="!formData.username || !formData.password ? 'info' : 'primary'" @click="submitClick">
  23. <text class="mr-5">登</text>
  24. <text class="ml-5">录</text>
  25. </button>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import {ref, onMounted} from "vue";
  32. import {onLoad, onUnload} from '@dcloudio/uni-app'
  33. import {getStorage, setStorage} from "@/utils/storage";
  34. import {useAppStore} from "@/store";
  35. import {userLogin} from "@/store/user";
  36. import {getObjVal} from "js-fast-way";
  37. const store = useAppStore()
  38. const webStyle = ref({
  39. width: '1px',
  40. height: '1px',
  41. })
  42. onLoad(() => {
  43. const user_info = getStorage('login_user_info');
  44. if (getObjVal(user_info)) {
  45. formData.value = user_info
  46. }
  47. //清除所有缓存
  48. store.clearStoreData()
  49. //关闭引导页
  50. setTimeout(() => {
  51. setStorage('app_guide', true);
  52. if (getObjVal(user_info)) {
  53. setStorage('login_user_info', user_info);
  54. }
  55. }, 1000)
  56. })
  57. //渲染完成
  58. onMounted(() => {
  59. // #ifdef H5
  60. window.addEventListener('message', handleMessage);
  61. // #endif
  62. })
  63. const handleMessage = (event) => {
  64. let msg = {};
  65. // #ifdef H5
  66. if (event.data && event.data.data && event.data.data.arg) {
  67. msg = event.data.data.arg
  68. }
  69. // #endif
  70. // #ifdef APP-PLUS
  71. msg = event.detail.data[0]
  72. // #endif
  73. if (msg.source === 'animation-web') {
  74. if (msg.type === "on-animation") {
  75. isAnimation(msg.data)
  76. }
  77. }
  78. }
  79. //判断动画
  80. const isAnimation = (data) => {
  81. console.log('动画结束,耗时:', data)
  82. if (data > 1500) {
  83. store.setAnimation(false)
  84. } else {
  85. store.setAnimation(true)
  86. }
  87. }
  88. //登录表单
  89. const formData = ref({
  90. tenantId: "000000",
  91. username: '',
  92. password: '',
  93. type: "account"
  94. })
  95. //登录
  96. const submitClick = () => {
  97. const {username, password} = formData.value
  98. if (!username) {
  99. uni.showToast({
  100. title: '请先输入登录账户',
  101. icon: 'none',
  102. duration: 3000
  103. });
  104. } else if (!password) {
  105. uni.showToast({
  106. title: '请先输入登录密码',
  107. icon: 'none',
  108. duration: 3000
  109. });
  110. } else {
  111. userLogin(formData.value).then((res) => {
  112. uni.showToast({
  113. title: '登录成功',
  114. duration: 2000,
  115. mask: true
  116. });
  117. //跳转登录
  118. setTimeout(() => {
  119. uni.switchTab({
  120. url: '/pages/index/index'
  121. })
  122. }, 2000);
  123. }).catch(({msg}) => {
  124. uni.showToast({
  125. title: msg,
  126. icon: 'none'
  127. });
  128. })
  129. }
  130. }
  131. onUnload(()=>{
  132. // #ifdef H5
  133. window.removeEventListener('message', handleMessage);
  134. // #endif
  135. })
  136. </script>
  137. <style lang="scss" scoped>
  138. page {
  139. height: 100%;
  140. }
  141. @import "@/style/login/login.scoped.scss";
  142. </style>
  143. <style lang="scss">
  144. @import "@/style/login/login.scss";
  145. </style>