login.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 :update-title="false" 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. // #ifdef APP-PLUS
  58. //ios 禁用缓存,测试生效!!
  59. let cache1 = plus.ios.newObject('NSURLCache');
  60. let cache = plus.ios.invoke(cache1, 'sharedURLCache');
  61. plus.ios.invoke(cache, 'removeAllCachedResponses');
  62. plus.ios.invoke(cache, 'setDiskCapacity:', 0);
  63. plus.ios.invoke(cache, 'setMemoryCapacity:', 0);
  64. //安卓端缓存清理。
  65. plus.cache.clear();
  66. // #endif
  67. }, 1000)
  68. })
  69. //渲染完成
  70. onMounted(() => {
  71. // #ifdef H5
  72. window.addEventListener('message', handleMessage);
  73. // #endif
  74. })
  75. const handleMessage = (event) => {
  76. let msg = {};
  77. // #ifdef H5
  78. if (event.data && event.data.data && event.data.data.arg) {
  79. msg = event.data.data.arg
  80. }
  81. // #endif
  82. // #ifdef APP-PLUS
  83. msg = event.detail.data[0]
  84. // #endif
  85. if (msg.source === 'animation-web') {
  86. if (msg.type === "on-animation") {
  87. isAnimation(msg.data)
  88. }
  89. }
  90. }
  91. //判断动画
  92. const isAnimation = (data) => {
  93. console.log('动画结束,耗时:', data)
  94. if (data > 1500) {
  95. store.setAnimation(false)
  96. } else {
  97. store.setAnimation(true)
  98. isDotShow.value = true
  99. }
  100. }
  101. //登录表单
  102. const formData = ref({
  103. tenantId: "000000",
  104. username: '',
  105. password: '',
  106. type: "account"
  107. })
  108. //登录
  109. const submitClick = () => {
  110. const {username, password} = formData.value
  111. if (!username) {
  112. uni.showToast({
  113. title: '请先输入登录账户',
  114. icon: 'none',
  115. duration: 3000
  116. });
  117. } else if (!password) {
  118. uni.showToast({
  119. title: '请先输入登录密码',
  120. icon: 'none',
  121. duration: 3000
  122. });
  123. } else {
  124. userLogin(formData.value).then((res) => {
  125. uni.showToast({
  126. title: '登录成功',
  127. duration: 2000,
  128. mask: true
  129. });
  130. //跳转登录
  131. setTimeout(() => {
  132. uni.switchTab({
  133. url: '/pages/index/index'
  134. })
  135. }, 2000);
  136. })
  137. }
  138. }
  139. onUnload(()=>{
  140. // #ifdef H5
  141. window.removeEventListener('message', handleMessage);
  142. // #endif
  143. })
  144. </script>
  145. <style lang="scss" scoped>
  146. page {
  147. height: 100%;
  148. }
  149. @import "@/style/login/login.scoped.scss";
  150. </style>
  151. <style lang="scss">
  152. @import "@/style/login/login.scss";
  153. </style>