login.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <view class="normal-login-container">
  3. <image
  4. src="/static/login13785@1x.png"
  5. mode="widthFix"
  6. class="wave-img"
  7. ></image>
  8. <view
  9. class="logo-content"
  10. :style="`margin-top: ${globalData.navBarHeight}px`"
  11. >
  12. <image :src="imagePath" mode="aspectFit" class="logo-image"></image>
  13. <text class="title">金邻助家</text>
  14. </view>
  15. <image
  16. src="/static/13779@1x.png"
  17. mode="widthFix"
  18. class="house-illustration"
  19. ></image>
  20. <view class="slogan-content">
  21. <text class="slogan-text">着力打造全国居家服务行业标准</text>
  22. <text class="slogan-text">和建立综合信用评价体系</text>
  23. </view>
  24. <view class="actions-container">
  25. <up-button @click="handleLogin" :customStyle="WeChat"
  26. >微信授权登录</up-button
  27. >
  28. <view class="xieyi text-center">
  29. <up-checkbox
  30. label="我已认真阅读、理解并同意"
  31. name="agree"
  32. usedAlone
  33. v-model="checkboxValue"
  34. class="text-grey1"
  35. >
  36. </up-checkbox>
  37. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  38. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup>
  44. import { ref, reactive, onMounted } from 'vue'
  45. import { useRouter } from 'vue-router' // 根据实际情况选择路由库
  46. import store from '@/store'
  47. import { onShow } from '@dcloudio/uni-app'
  48. const imagePath = '/static/9efd1.png' // Path to the logo image (red tree)
  49. // 获取全局配置
  50. // const globalConfig = getApp().globalData.config;
  51. const register = ref(false) // 用户注册开关
  52. const loginForm = reactive({
  53. username: '',
  54. password: '',
  55. code: '',
  56. uuid: '',
  57. })
  58. const checkboxValue = ref(false)
  59. const globalData = ref({
  60. statusBarHeight: 47,
  61. navBarHeight: 91,
  62. })
  63. // const codeUrl = ref(""); // Not used in the new design
  64. // const captchaEnabled = ref(true); // Not used in the new design
  65. const router = useRouter()
  66. // 用户注册 - assuming this might be needed later, keeping it
  67. const handleUserRegister = () => {
  68. router.push('/pages/register') // 替换为实际的路由跳转逻辑
  69. }
  70. const WeChat = {
  71. width: '530rpx',
  72. height: '96rpx',
  73. opacity: 1,
  74. background: '#8B4F2D',
  75. color: '#FFFFFF',
  76. borderRadius: '48rpx',
  77. fontWeight: '700px',
  78. fontSize: '32rpx',
  79. marginLeft: 'auto',
  80. marginRight: 'auto',
  81. marginBottom: '10rpx',
  82. display: 'flex',
  83. justifyContent: 'center',
  84. alignItems: 'center',
  85. border: 'none',
  86. boxShadow: 'none',
  87. }
  88. // 隐私协议
  89. const handlePrivacy = () => {
  90. uni.navigateTo({
  91. url: '/pages_home/pages/login/index',
  92. })
  93. }
  94. // 用户协议
  95. const handleUserAgrement = () => {
  96. uni.navigateTo({
  97. url: '/pages_home/pages/login/user',
  98. })
  99. }
  100. // 登录方法
  101. const handleLogin = async () => {
  102. console.log('checkboxValue', checkboxValue)
  103. if (!checkboxValue.value) {
  104. uni.showToast({
  105. title: '请先阅读并同意相关协议',
  106. icon: 'none',
  107. })
  108. return
  109. }
  110. uni.showLoading({
  111. title: '登录中,请耐心等待...',
  112. }) // 使用uni-app的loading方法替代$modal.loading
  113. // 获取服务商信息
  114. uni.getProvider({
  115. service: 'oauth',
  116. success: (res) => {
  117. console.log(res)
  118. },
  119. })
  120. // 获取code
  121. uni.login({
  122. provider: 'weixin',
  123. success: (res) => {
  124. if (res.code == 500) {
  125. uni.showLoading({
  126. title: '系统暂未开发,敬请期待',
  127. })
  128. } else if (res.code == 400) {
  129. uni.showLoading({
  130. title: '系统暂未开放',
  131. })
  132. }
  133. loginForm.code = res.code
  134. // 获取用户信息
  135. uni.getUserInfo({
  136. success: (res) => {
  137. console.log('用户信息', res)
  138. },
  139. })
  140. pwdLogin()
  141. uni.hideLoading()
  142. },
  143. })
  144. }
  145. // 密码登录
  146. const pwdLogin = async () => {
  147. if (!store) {
  148. console.error('Store is not defined')
  149. return
  150. }
  151. store.dispatch('Login', loginForm).then(() => {
  152. // uni.hideLoading(); // 关闭加载提示
  153. loginSuccess()
  154. })
  155. }
  156. // 登录成功后,处理函数
  157. const loginSuccess = () => {
  158. store.dispatch('GetInfo').then((res) => {
  159. console.log(store.state.user.userOrWorker, '>>>>99')
  160. if (store.state.user.userOrWorker == 0) {
  161. uni.reLaunch({
  162. url: '/pages/UserSelection',
  163. })
  164. return
  165. }
  166. uni.setStorageSync('userType', store.state.user.userOrWorker)
  167. uni.switchTab({
  168. url: '/pages/index',
  169. })
  170. })
  171. }
  172. // 获取胶囊位置信息
  173. const getSystemInfo = () => {
  174. uni.getSystemInfo({
  175. success: (res) => {
  176. const statusBarHeight = res.statusBarHeight
  177. const navBarHeight =
  178. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  179. globalData.value = { statusBarHeight, navBarHeight }
  180. },
  181. })
  182. }
  183. onShow(() => {
  184. getSystemInfo()
  185. })
  186. // 页面加载时
  187. onMounted(() => {
  188. uni.setStorageSync('userType', 0)
  189. // 设置状态栏为透明
  190. uni.setNavigationBarColor({
  191. frontColor: '#ffffff',
  192. backgroundColor: 'rgba(0,0,0,0)',
  193. animation: {
  194. duration: 0,
  195. timingFunc: 'easeIn',
  196. },
  197. })
  198. getSystemInfo()
  199. })
  200. </script>
  201. <style lang="scss" scoped>
  202. .normal-login-container {
  203. // border: 2px solid red;
  204. width: 100vw;
  205. height: 100vh;
  206. // width: 100vw;
  207. // height: 100vh;
  208. border-radius: 48rpx;
  209. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  210. position: relative;
  211. overflow-x: hidden;
  212. .wave-img {
  213. position: absolute;
  214. top: 0;
  215. left: 0;
  216. width: 100vw;
  217. height: 100vh;
  218. }
  219. display: flex;
  220. flex-direction: column;
  221. align-items: center;
  222. }
  223. .logo-content {
  224. display: flex;
  225. flex-direction: column;
  226. align-items: center;
  227. position: relative;
  228. z-index: 1;
  229. .logo-image {
  230. width: 90px;
  231. height: 78px;
  232. margin-top: 47rpx;
  233. margin-bottom: -10rpx;
  234. margin-right: 300rpx;
  235. margin-left: 300rpx;
  236. }
  237. .title {
  238. width: 184rpx;
  239. height: 60rpx;
  240. font-family: Poppins;
  241. font-size: 46rpx;
  242. font-weight: 400;
  243. line-height: 60rpx;
  244. letter-spacing: normal;
  245. color: #ffffff;
  246. z-index: 1;
  247. margin-top: 0;
  248. margin-bottom: 77rpx;
  249. margin-right: 300rpx;
  250. margin-left: 300rpx;
  251. }
  252. }
  253. .house-illustration {
  254. width: 720rpx;
  255. height: 334rpx;
  256. margin-top: 0;
  257. margin-bottom: 50rpx;
  258. margin-right: 136rpx;
  259. margin-left: 136rpx;
  260. }
  261. .slogan-content {
  262. margin-top: 0;
  263. margin-bottom: 380rpx;
  264. margin-right: 300rpx;
  265. margin-left: 300rpx;
  266. z-index: 1;
  267. .slogan-text {
  268. display: flex;
  269. flex-direction: column;
  270. align-items: center;
  271. width: 448rpx;
  272. height: 52rpx;
  273. font-family: Poppins;
  274. font-size: 32rpx;
  275. font-weight: 600;
  276. line-height: 52rpx;
  277. text-align: center;
  278. letter-spacing: normal;
  279. color: #824727;
  280. }
  281. }
  282. .actions-container {
  283. display: flex;
  284. flex-direction: column;
  285. align-items: center;
  286. width: 100%;
  287. z-index: 1;
  288. }
  289. .xieyi {
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. flex-wrap: wrap;
  294. }
  295. .text-blue {
  296. color: #1976d2;
  297. margin: 0 4rpx;
  298. }
  299. .text-grey1 {
  300. color: #333333;
  301. }
  302. .text-center {
  303. text-align: center;
  304. }
  305. </style>