login.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="back-icon" :style="`margin-top: ${globalData.statusBarHeight}px`">
  4. <up-icon name="arrow-left" size="24" @click="backClick"></up-icon>
  5. </view>
  6. <image src="/static/login13785@1x.png" mode="widthFix" class="wave-img"></image>
  7. <view class="logo-content" :style="`margin-top: ${globalData.navBarHeight}px`">
  8. <image :src="imagePath" mode="aspectFit" class="logo-image"></image>
  9. <text class="title">金邻助家</text>
  10. </view>
  11. <view class="slogan-content">
  12. <text class="slogan-text">着力打造全国居家服务行业标准</text>
  13. <text class="slogan-text">和建立综合信用评价体系</text>
  14. </view>
  15. <image src="/static/13779@1x.png" mode="widthFix" class="house-illustration"></image>
  16. <view class="actions-container">
  17. <up-button @click="onLogin" :customStyle="WeChat">微信授权登录</up-button>
  18. <view class="xieyi text-center">
  19. <up-checkbox-group v-model="checkboxValue">
  20. <up-checkbox label="我已认真阅读、理解并同意" name="agree" usedAlone @change="onCheckboxChange" class="text-grey1">
  21. </up-checkbox>
  22. </up-checkbox-group>
  23. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  24. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import { ref, reactive, onMounted } from 'vue'
  31. import { useRouter } from 'vue-router' // 根据实际情况选择路由库
  32. import store from '@/store'
  33. import { onShow, onLoad } from '@dcloudio/uni-app'
  34. import {
  35. userOrWorker,
  36. } from '@/api/login';
  37. import { getUnlimitedQRCode } from '@/api/qrcode'
  38. const imagePath = '/static/9efd1.png'
  39. // 获取全局配置
  40. // const globalConfig = getApp().globalData.config;
  41. const loginForm = reactive({
  42. username: '',
  43. password: '',
  44. code: '',
  45. uuid: '',
  46. referrerType: '',
  47. referrerId: '',
  48. latitude: 0,
  49. longitude: 0,
  50. })
  51. const checkboxValue = ref(false)
  52. const globalData = ref({
  53. statusBarHeight: 47,
  54. navBarHeight: 91,
  55. })
  56. const router = useRouter()
  57. // 获取小程序码参数
  58. onLoad((options) => {
  59. // 处理从二维码扫描进入的场景
  60. // debugger
  61. // if (options.scene) {
  62. console.log('options.scene:>>>>>>>123123s', options.scene)
  63. const scene = decodeURIComponent(options.scene)
  64. const params = scene.split(':')
  65. if (params.length >= 2) {
  66. loginForm.referrerType = params[0]
  67. loginForm.referrerId = params[1]
  68. console.log('从二维码获取参数:', loginForm.referrerType, loginForm.referrerId)
  69. }
  70. // }
  71. // 如果有直接传入的参数也可以获取
  72. if (options.referrerType) {
  73. loginForm.referrerType = options.referrerType
  74. }
  75. if (options.referrerId) {
  76. loginForm.referrerId = options.referrerId
  77. }
  78. })
  79. // 用户注册 - assuming this might be needed later, keeping it
  80. const handleUserRegister = () => {
  81. router.push('/pages/register') // 替换为实际的路由跳转逻辑
  82. }
  83. const WeChat = {
  84. width: '530rpx',
  85. height: '96rpx',
  86. opacity: 1,
  87. background: '#8B4F2D',
  88. color: '#FFFFFF',
  89. borderRadius: '48rpx',
  90. fontWeight: '700px',
  91. fontSize: '32rpx',
  92. marginLeft: 'auto',
  93. marginRight: 'auto',
  94. marginBottom: '10rpx',
  95. display: 'flex',
  96. justifyContent: 'center',
  97. alignItems: 'center',
  98. border: 'none',
  99. boxShadow: 'none',
  100. }
  101. // 隐私协议
  102. const handlePrivacy = () => {
  103. uni.navigateTo({
  104. url: '/pages_home/pages/login/index',
  105. })
  106. }
  107. // 用户协议
  108. const handleUserAgrement = () => {
  109. uni.navigateTo({
  110. url: '/pages_home/pages/login/user',
  111. })
  112. }
  113. // 获取模糊位置信息
  114. const getFuzzyLocation = () => {
  115. return new Promise((resolve, reject) => {
  116. wx.getFuzzyLocation({
  117. type: 'gcj02',
  118. success: (res) => {
  119. console.log('模糊位置获取成功:', res)
  120. // 确保经纬度是number类型
  121. loginForm.latitude = Number(res.latitude)
  122. loginForm.longitude = Number(res.longitude)
  123. resolve(res)
  124. },
  125. fail: (err) => {
  126. console.error('模糊位置获取失败:', err)
  127. // 位置获取失败时,设为默认值0
  128. loginForm.latitude = 0
  129. loginForm.longitude = 0
  130. resolve({
  131. latitude: 0,
  132. longitude: 0
  133. })
  134. }
  135. })
  136. })
  137. }
  138. // 登录方法
  139. const onLogin = () => {
  140. uni.$u.debounce(handleLogin, 300)
  141. }
  142. const handleLogin = async () => {
  143. if (!checkboxValue.value) {
  144. uni.showToast({
  145. title: '请先阅读并同意相关协议',
  146. icon: 'none',
  147. })
  148. return
  149. }
  150. uni.showLoading({
  151. title: '登录中,请耐心等待...',
  152. }) // 使用uni-app的loading方法替代$modal.loading
  153. try {
  154. // 获取模糊位置信息
  155. await getFuzzyLocation()
  156. console.log('登录位置信息:', loginForm.latitude, loginForm.longitude)
  157. } catch (err) {
  158. console.log('位置获取失败,继续登录流程')
  159. }
  160. // 获取code
  161. uni.login({
  162. provider: 'weixin',
  163. success: (res) => {
  164. if (res.code == 500) {
  165. uni.showLoading({
  166. title: '系统暂未开发,敬请期待',
  167. })
  168. } else if (res.code == 400) {
  169. uni.showLoading({
  170. title: '系统暂未开放',
  171. })
  172. }
  173. loginForm.code = res.code
  174. pwdLogin()
  175. uni.hideLoading()
  176. },
  177. })
  178. }
  179. // 密码登录
  180. const pwdLogin = async () => {
  181. if (!store) {
  182. console.error('Store is not defined')
  183. return
  184. }
  185. // 确保经纬度已添加到loginForm
  186. console.log('发送登录请求,经纬度:', loginForm.latitude, loginForm.longitude)
  187. store.dispatch('Login', loginForm).then(() => {
  188. loginSuccess()
  189. })
  190. }
  191. // 登录成功后,处理函数
  192. const loginSuccess = () => {
  193. store.dispatch('GetInfo').then((res) => {
  194. uni.setStorageSync('userType', store.state.user.userOrWorker)
  195. uni.setStorageSync('userId', res.user.userId)
  196. userOrWorker({ userType: store.state.user.userOrWorker })
  197. .then(res => {
  198. uni.switchTab({
  199. url: '/pages/index',
  200. })
  201. })
  202. .catch(err => {
  203. console.error('设置失败:', err);
  204. });
  205. })
  206. }
  207. // 获取胶囊位置信息
  208. const getSystemInfo = () => {
  209. uni.getSystemInfo({
  210. success: (res) => {
  211. const statusBarHeight = res.statusBarHeight
  212. const navBarHeight =
  213. (res.platform === 'android') ? 48 : 44 + res.statusBarHeight
  214. globalData.value = { statusBarHeight, navBarHeight }
  215. },
  216. })
  217. }
  218. onShow(() => {
  219. getSystemInfo()
  220. })
  221. // 页面加载时
  222. onMounted(() => {
  223. uni.setStorageSync('userType', 0)
  224. // 设置状态栏为透明
  225. uni.setNavigationBarColor({
  226. frontColor: '#ffffff',
  227. backgroundColor: 'rgba(0,0,0,0)',
  228. animation: {
  229. duration: 0,
  230. timingFunc: 'easeIn',
  231. },
  232. })
  233. getSystemInfo()
  234. })
  235. const onCheckboxChange = (value) => {
  236. console.log('复选框状态改变:', value)
  237. checkboxValue.value = value
  238. }
  239. const backClick =() =>{
  240. console.log('back');
  241. wx.navigateBack({
  242. delta: 1, // 返回上一页
  243. });
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .back-icon {
  248. height: 108rpx;
  249. position: fixed;
  250. width: 100%;
  251. padding: 0 34rpx;
  252. display: flex;
  253. align-items: center;
  254. justify-content: space-between;
  255. z-index: 99;
  256. }
  257. .normal-login-container {
  258. width: 100vw;
  259. height: 100vh;
  260. border-radius: 48rpx;
  261. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  262. position: relative;
  263. overflow-x: hidden;
  264. .wave-img {
  265. position: absolute;
  266. top: 0;
  267. left: 0;
  268. width: 100vw;
  269. height: 100vh;
  270. }
  271. display: flex;
  272. flex-direction: column;
  273. align-items: center;
  274. }
  275. .logo-content {
  276. display: flex;
  277. flex-direction: column;
  278. align-items: center;
  279. position: relative;
  280. z-index: 1;
  281. .logo-image {
  282. width: 232rpx;
  283. height: 201rpx;
  284. margin-top: 47rpx;
  285. margin-bottom: -10rpx;
  286. margin-right: 300rpx;
  287. margin-left: 300rpx;
  288. }
  289. .title {
  290. width: 360rpx;
  291. height: 128rpx;
  292. font-family: Poppins;
  293. font-size: 90rpx;
  294. font-weight: 600;
  295. line-height: 127.81rpx;
  296. letter-spacing: normal;
  297. color: #FFFFFF;
  298. z-index: 1;
  299. margin-top: 0;
  300. margin-bottom: 82rpx;
  301. margin-right: 195rpx;
  302. margin-left: 195rpx;
  303. }
  304. }
  305. .house-illustration {
  306. width: 720rpx;
  307. height: 334rpx;
  308. margin-top: 0;
  309. margin-bottom: 78rpx;
  310. margin-right: 136rpx;
  311. margin-left: 136rpx;
  312. }
  313. .slogan-content {
  314. margin-top: 0;
  315. margin-bottom: 235rpx;
  316. margin-right: 300rpx;
  317. margin-left: 300rpx;
  318. z-index: 1;
  319. .slogan-text {
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. width: 448rpx;
  324. height: 52rpx;
  325. font-family: Poppins;
  326. font-size: 32rpx;
  327. font-weight: 600;
  328. line-height: 52rpx;
  329. text-align: center;
  330. letter-spacing: normal;
  331. color: #824727;
  332. }
  333. }
  334. .actions-container {
  335. display: flex;
  336. flex-direction: column;
  337. align-items: center;
  338. width: 100%;
  339. z-index: 1;
  340. }
  341. .xieyi {
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. flex-wrap: wrap;
  346. }
  347. .text-blue {
  348. color: #1976d2;
  349. margin: 0 4rpx;
  350. }
  351. .text-grey1 {
  352. color: #333333;
  353. }
  354. .text-center {
  355. text-align: center;
  356. }
  357. </style>