login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. isDotShow.value = true
  68. }, 1000)
  69. })
  70. //渲染完成
  71. onMounted(() => {
  72. // #ifdef H5
  73. window.addEventListener('message', handleMessage);
  74. // #endif
  75. })
  76. const handleMessage = (event) => {
  77. let msg = {};
  78. // #ifdef H5
  79. if (event.data && event.data.data && event.data.data.arg) {
  80. msg = event.data.data.arg
  81. }
  82. // #endif
  83. // #ifdef APP-PLUS
  84. msg = event.detail.data[0]
  85. // #endif
  86. if (msg.source === 'animation-web') {
  87. if (msg.type === "on-animation") {
  88. isAnimation(msg.data)
  89. }
  90. }
  91. }
  92. //判断动画
  93. const isAnimation = (data) => {
  94. console.log('动画结束,耗时:', data)
  95. if (data > 1500) {
  96. store.setAnimation(false)
  97. } else {
  98. store.setAnimation(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. }).catch(({msg}) => {
  137. uni.showToast({
  138. title: msg,
  139. icon: 'none'
  140. });
  141. })
  142. }
  143. }
  144. onUnload(()=>{
  145. // #ifdef H5
  146. window.removeEventListener('message', handleMessage);
  147. // #endif
  148. })
  149. </script>
  150. <style lang="scss" scoped>
  151. page {
  152. height: 100%;
  153. }
  154. @import "@/style/login/login.scoped.scss";
  155. </style>
  156. <style lang="scss">
  157. @import "@/style/login/login.scss";
  158. </style>