login.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. // 使用字符串格式保留6位小数,避免parseFloat去除末尾的0
  121. const lat = res.latitude.toFixed(6)
  122. const lng = res.longitude.toFixed(6)
  123. // 在表单中保存为数字格式
  124. loginForm.latitude = Number(lat)
  125. loginForm.longitude = Number(lng)
  126. console.log('处理后的经纬度:', lat, lng)
  127. resolve({
  128. latitude: lat,
  129. longitude: lng
  130. })
  131. },
  132. fail: (err) => {
  133. console.error('模糊位置获取失败:', err)
  134. // 位置获取失败时,设为默认值0,也保留6位小数
  135. loginForm.latitude = 0
  136. loginForm.longitude = 0
  137. resolve({
  138. latitude: "0.000000",
  139. longitude: "0.000000"
  140. })
  141. }
  142. })
  143. })
  144. }
  145. // 登录方法
  146. const onLogin = () => {
  147. uni.$u.debounce(handleLogin, 300)
  148. }
  149. const handleLogin = async () => {
  150. if (!checkboxValue.value) {
  151. uni.showToast({
  152. title: '请先阅读并同意相关协议',
  153. icon: 'none',
  154. })
  155. return
  156. }
  157. uni.showLoading({
  158. title: '登录中,请耐心等待...',
  159. }) // 使用uni-app的loading方法替代$modal.loading
  160. try {
  161. // 获取模糊位置信息
  162. await getFuzzyLocation()
  163. console.log('登录位置信息:', loginForm.latitude, loginForm.longitude)
  164. } catch (err) {
  165. console.log('位置获取失败,继续登录流程')
  166. }
  167. // 获取code
  168. uni.login({
  169. provider: 'weixin',
  170. success: (res) => {
  171. if (res.code == 500) {
  172. uni.showLoading({
  173. title: '系统暂未开发,敬请期待',
  174. })
  175. } else if (res.code == 400) {
  176. uni.showLoading({
  177. title: '系统暂未开放',
  178. })
  179. }
  180. loginForm.code = res.code
  181. pwdLogin()
  182. uni.hideLoading()
  183. },
  184. })
  185. }
  186. // 密码登录
  187. const pwdLogin = async () => {
  188. if (!store) {
  189. console.error('Store is not defined')
  190. return
  191. }
  192. // 确保经纬度已添加到loginForm
  193. console.log('发送登录请求,经纬度:', loginForm.latitude, loginForm.longitude)
  194. store.dispatch('Login', loginForm).then(() => {
  195. loginSuccess()
  196. })
  197. }
  198. // 登录成功后,处理函数
  199. const loginSuccess = () => {
  200. store.dispatch('GetInfo').then((res) => {
  201. uni.setStorageSync('userType', store.state.user.userOrWorker)
  202. uni.setStorageSync('userId', res.user.userId)
  203. userOrWorker({ userType: store.state.user.userOrWorker })
  204. .then(res => {
  205. uni.switchTab({
  206. url: '/pages/index',
  207. })
  208. })
  209. .catch(err => {
  210. console.error('设置失败:', err);
  211. });
  212. })
  213. }
  214. // 获取胶囊位置信息
  215. const getSystemInfo = () => {
  216. uni.getSystemInfo({
  217. success: (res) => {
  218. const statusBarHeight = res.statusBarHeight
  219. const navBarHeight =
  220. (res.platform === 'android') ? 48 : 44 + res.statusBarHeight
  221. globalData.value = { statusBarHeight, navBarHeight }
  222. },
  223. })
  224. }
  225. onShow(() => {
  226. getSystemInfo()
  227. })
  228. // 页面加载时
  229. onMounted(() => {
  230. uni.setStorageSync('userType', 0)
  231. // 设置状态栏为透明
  232. uni.setNavigationBarColor({
  233. frontColor: '#ffffff',
  234. backgroundColor: 'rgba(0,0,0,0)',
  235. animation: {
  236. duration: 0,
  237. timingFunc: 'easeIn',
  238. },
  239. })
  240. getSystemInfo()
  241. })
  242. const onCheckboxChange = (value) => {
  243. console.log('复选框状态改变:', value)
  244. checkboxValue.value = value
  245. }
  246. const backClick =() =>{
  247. console.log('back');
  248. wx.navigateBack({
  249. delta: 1, // 返回上一页
  250. });
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. .back-icon {
  255. height: 108rpx;
  256. position: fixed;
  257. width: 100%;
  258. padding: 0 34rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. z-index: 99;
  263. }
  264. .normal-login-container {
  265. width: 100vw;
  266. height: 100vh;
  267. border-radius: 48rpx;
  268. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  269. position: relative;
  270. overflow-x: hidden;
  271. .wave-img {
  272. position: absolute;
  273. top: 0;
  274. left: 0;
  275. width: 100vw;
  276. height: 100vh;
  277. }
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. }
  282. .logo-content {
  283. display: flex;
  284. flex-direction: column;
  285. align-items: center;
  286. position: relative;
  287. z-index: 1;
  288. .logo-image {
  289. width: 232rpx;
  290. height: 201rpx;
  291. margin-top: 47rpx;
  292. margin-bottom: -10rpx;
  293. margin-right: 300rpx;
  294. margin-left: 300rpx;
  295. }
  296. .title {
  297. width: 360rpx;
  298. height: 128rpx;
  299. font-family: Poppins;
  300. font-size: 90rpx;
  301. font-weight: 600;
  302. line-height: 127.81rpx;
  303. letter-spacing: normal;
  304. color: #FFFFFF;
  305. z-index: 1;
  306. margin-top: 0;
  307. margin-bottom: 82rpx;
  308. margin-right: 195rpx;
  309. margin-left: 195rpx;
  310. }
  311. }
  312. .house-illustration {
  313. width: 720rpx;
  314. height: 334rpx;
  315. margin-top: 0;
  316. margin-bottom: 78rpx;
  317. margin-right: 136rpx;
  318. margin-left: 136rpx;
  319. }
  320. .slogan-content {
  321. margin-top: 0;
  322. margin-bottom: 235rpx;
  323. margin-right: 300rpx;
  324. margin-left: 300rpx;
  325. z-index: 1;
  326. .slogan-text {
  327. display: flex;
  328. flex-direction: column;
  329. align-items: center;
  330. width: 448rpx;
  331. height: 52rpx;
  332. font-family: Poppins;
  333. font-size: 32rpx;
  334. font-weight: 600;
  335. line-height: 52rpx;
  336. text-align: center;
  337. letter-spacing: normal;
  338. color: #824727;
  339. }
  340. }
  341. .actions-container {
  342. display: flex;
  343. flex-direction: column;
  344. align-items: center;
  345. width: 100%;
  346. z-index: 1;
  347. }
  348. .xieyi {
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. flex-wrap: wrap;
  353. }
  354. .text-blue {
  355. color: #1976d2;
  356. margin: 0 4rpx;
  357. }
  358. .text-grey1 {
  359. color: #333333;
  360. }
  361. .text-center {
  362. text-align: center;
  363. }
  364. </style>