login.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="hc-login-box relative h-full p-4">
  3. <view class="hc-dot-box" v-show="isDotShow">
  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. //初始变量
  38. const store = useAppStore()
  39. const webStyle = ref({
  40. width: '1px',
  41. height: '1px',
  42. })
  43. const isDotShow = ref(false)
  44. onLoad(() => {
  45. const user_info = getStorage('login_user_info');
  46. if (getObjVal(user_info)) {
  47. formData.value = user_info
  48. }
  49. //清除所有缓存
  50. store.clearStoreData()
  51. //关闭引导页
  52. setTimeout(() => {
  53. setStorage('app_guide', true);
  54. if (getObjVal(user_info)) {
  55. setStorage('login_user_info', user_info);
  56. }
  57. isDotShow.value = true
  58. }, 1000)
  59. })
  60. //渲染完成
  61. onMounted(() => {
  62. // #ifdef H5
  63. window.addEventListener('message', handleMessage);
  64. // #endif
  65. })
  66. const handleMessage = (event) => {
  67. let msg = {};
  68. // #ifdef H5
  69. if (event.data && event.data.data && event.data.data.arg) {
  70. msg = event.data.data.arg
  71. }
  72. // #endif
  73. // #ifdef APP-PLUS
  74. msg = event.detail.data[0]
  75. // #endif
  76. if (msg.source === 'animation-web') {
  77. if (msg.type === "on-animation") {
  78. isAnimation(msg.data)
  79. }
  80. }
  81. }
  82. //判断动画
  83. const isAnimation = (data) => {
  84. console.log('动画结束,耗时:', data)
  85. if (data > 1500) {
  86. store.setAnimation(false)
  87. } else {
  88. store.setAnimation(true)
  89. }
  90. }
  91. //登录表单
  92. const formData = ref({
  93. tenantId: "000000",
  94. username: '',
  95. password: '',
  96. type: "account"
  97. })
  98. //登录
  99. const submitClick = () => {
  100. const {username, password} = formData.value
  101. if (!username) {
  102. uni.showToast({
  103. title: '请先输入登录账户',
  104. icon: 'none',
  105. duration: 3000
  106. });
  107. } else if (!password) {
  108. uni.showToast({
  109. title: '请先输入登录密码',
  110. icon: 'none',
  111. duration: 3000
  112. });
  113. } else {
  114. userLogin(formData.value).then((res) => {
  115. uni.showToast({
  116. title: '登录成功',
  117. duration: 2000,
  118. mask: true
  119. });
  120. //跳转登录
  121. setTimeout(() => {
  122. uni.switchTab({
  123. url: '/pages/index/index'
  124. })
  125. }, 2000);
  126. }).catch(({msg}) => {
  127. uni.showToast({
  128. title: msg,
  129. icon: 'none'
  130. });
  131. })
  132. }
  133. }
  134. onUnload(()=>{
  135. // #ifdef H5
  136. window.removeEventListener('message', handleMessage);
  137. // #endif
  138. })
  139. </script>
  140. <style lang="scss" scoped>
  141. page {
  142. height: 100%;
  143. }
  144. @import "@/style/login/login.scoped.scss";
  145. </style>
  146. <style lang="scss">
  147. @import "@/style/login/login.scss";
  148. </style>