login.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="wave-container">
  4. <image
  5. src="/static/login 13780@1x.png"
  6. mode="widthFix"
  7. class="wave-img"
  8. ></image>
  9. </view>
  10. <view class="logo-content">
  11. <image :src="imagePath" mode="aspectFit" class="logo-image"></image>
  12. <text class="title">金邻助家</text>
  13. </view>
  14. <image
  15. src="/static/13779@1x.png"
  16. mode="widthFix"
  17. class="house-illustration"
  18. ></image>
  19. <view class="slogan-content">
  20. <text class="slogan-text">着力打造全国居家服务行业标准</text>
  21. <text class="slogan-text">和建立综合信用评价体系</text>
  22. </view>
  23. <view class="actions-container">
  24. <up-button
  25. custom-style="{ 'background-color': '#623F34', 'color': '#FFFFFF', 'border-radius': '25px', 'height': '50px', 'line-height': '50px', 'fontSize': '18px' }"
  26. class="login-button"
  27. @click="handleLogin"
  28. >微信授权登录</up-button
  29. >
  30. <view class="xieyi text-center">
  31. <text class="text-grey1">登录即代表同意</text>
  32. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  33. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script setup>
  39. import { ref, reactive, onMounted } from 'vue'
  40. import { useRouter } from 'vue-router' // 根据实际情况选择路由库
  41. import store from '@/store'
  42. const imagePath = '/static/9efd1.png' // Path to the logo image (red tree)
  43. // 获取全局配置
  44. // const globalConfig = getApp().globalData.config;
  45. const register = ref(false) // 用户注册开关
  46. const loginForm = reactive({
  47. username: '',
  48. password: '',
  49. code: '',
  50. uuid: '',
  51. })
  52. // const codeUrl = ref(""); // Not used in the new design
  53. // const captchaEnabled = ref(true); // Not used in the new design
  54. const router = useRouter()
  55. // 用户注册 - assuming this might be needed later, keeping it
  56. const handleUserRegister = () => {
  57. router.push('/pages/register') // 替换为实际的路由跳转逻辑
  58. }
  59. // 隐私协议
  60. const handlePrivacy = () => {
  61. uni.navigateTo({
  62. url: '/pages_home/pages/login/index',
  63. })
  64. }
  65. // 用户协议
  66. const handleUserAgrement = () => {
  67. uni.navigateTo({
  68. url: '/pages_home/pages/login/user',
  69. })
  70. }
  71. // 登录方法
  72. const handleLogin = async () => {
  73. uni.showLoading({
  74. title: '登录中,请耐心等待...',
  75. }) // 使用uni-app的loading方法替代$modal.loading
  76. // 获取服务商信息
  77. uni.getProvider({
  78. service: 'oauth',
  79. success: (res) => {
  80. console.log(res)
  81. },
  82. })
  83. // 获取code
  84. uni.login({
  85. provider: 'weixin',
  86. success: (res) => {
  87. if (res.code == 500) {
  88. uni.showLoading({
  89. title: '系统暂未开发,敬请期待',
  90. })
  91. } else if (res.code == 400) {
  92. uni.showLoading({
  93. title: '系统暂未开放',
  94. })
  95. }
  96. loginForm.code = res.code
  97. // 获取用户信息
  98. uni.getUserInfo({
  99. success: (res) => {
  100. console.log('用户信息', res)
  101. },
  102. })
  103. pwdLogin()
  104. uni.hideLoading()
  105. },
  106. })
  107. }
  108. // 密码登录
  109. const pwdLogin = async () => {
  110. if (!store) {
  111. console.error('Store is not defined')
  112. return
  113. }
  114. store.dispatch('Login', loginForm).then(() => {
  115. // uni.hideLoading(); // 关闭加载提示
  116. loginSuccess()
  117. })
  118. }
  119. // 登录成功后,处理函数
  120. const loginSuccess = () => {
  121. store.dispatch('GetInfo').then((res) => {
  122. console.log(store.state.user.userOrWorker, '>>>>99')
  123. if (store.state.user.userOrWorker == 0) {
  124. uni.reLaunch({
  125. url: '/pages/UserSelection',
  126. })
  127. return
  128. }
  129. uni.setStorageSync('userType', store.state.user.userOrWorker)
  130. uni.switchTab({
  131. url: '/pages/index',
  132. })
  133. })
  134. }
  135. // 页面加载时
  136. onMounted(() => {
  137. uni.setStorageSync('userType', 0)
  138. // 设置状态栏为透明
  139. uni.setNavigationBarColor({
  140. frontColor: '#ffffff',
  141. backgroundColor: 'rgba(0,0,0,0)',
  142. animation: {
  143. duration: 0,
  144. timingFunc: 'easeIn'
  145. }
  146. })
  147. })
  148. </script>
  149. <style lang="scss" scoped>
  150. .wave-container{
  151. width: 100%;
  152. height: 100%;
  153. position: fixed;
  154. top: 0;
  155. left: 0;
  156. z-index: 0;
  157. .wave-img{
  158. width: 100%;
  159. height: 100%;
  160. }
  161. }
  162. .normal-login-container {
  163. width: 100%;
  164. min-height: 100vh;
  165. position: relative;
  166. display: flex;
  167. flex-direction: column;
  168. align-items: center;
  169. overflow: hidden;
  170. padding-top: var(--status-bar-height);
  171. box-sizing: border-box;
  172. }
  173. .logo-content {
  174. margin-top: calc(100rpx + var(--status-bar-height));
  175. display: flex;
  176. flex-direction: column;
  177. align-items: center;
  178. position: relative;
  179. z-index: 1;
  180. .logo-image {
  181. width: 90rpx;
  182. height: 90rpx;
  183. margin-bottom: 20rpx;
  184. }
  185. .title {
  186. font-family: PingFang SC;
  187. font-size: 38rpx;
  188. font-weight: 600;
  189. line-height: 38rpx;
  190. color: #ffffff;
  191. text-align: center;
  192. text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  193. }
  194. }
  195. .house-illustration {
  196. width: 560rpx;
  197. margin-top: 60rpx;
  198. margin-bottom: 40rpx;
  199. position: relative;
  200. z-index: 1;
  201. }
  202. .slogan-content {
  203. text-align: center;
  204. position: relative;
  205. z-index: 1;
  206. .slogan-text {
  207. font-size: 28rpx;
  208. color: #593931;
  209. line-height: 38rpx;
  210. display: block;
  211. }
  212. }
  213. .actions-container {
  214. width: 100%;
  215. padding: 0 80rpx;
  216. position: absolute;
  217. bottom: 80rpx;
  218. left: 0;
  219. z-index: 1;
  220. .login-button {
  221. width: 100%;
  222. height: 88rpx;
  223. line-height: 88rpx;
  224. border-radius: 44rpx !important;
  225. background-color: #623f34 !important;
  226. color: #ffffff !important;
  227. font-size: 32rpx !important;
  228. font-weight: 400;
  229. }
  230. .xieyi {
  231. margin-top: 24rpx;
  232. text-align: center;
  233. .text-grey1 {
  234. font-size: 24rpx;
  235. color: #333333;
  236. }
  237. .text-blue {
  238. font-size: 24rpx;
  239. color: #1a88ff;
  240. margin: 0 4rpx;
  241. }
  242. }
  243. }
  244. </style>