login.vue 9.2 KB

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