login.vue 9.3 KB

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