login.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="normal-login-container">
  3. <image src="/static/login13785@1x.png" mode="widthFix" class="wave-img"></image>
  4. <view class="logo-content" :style="`margin-top: ${globalData.navBarHeight}px`">
  5. <image :src="imagePath" mode="aspectFit" class="logo-image"></image>
  6. <text class="title">金邻助家</text>
  7. </view>
  8. <view class="slogan-content">
  9. <text class="slogan-text">着力打造全国居家服务行业标准</text>
  10. <text class="slogan-text">和建立综合信用评价体系</text>
  11. </view>
  12. <image src="/static/13779@1x.png" mode="widthFix" class="house-illustration"></image>
  13. <view class="actions-container">
  14. <up-button @click="onLogin" :customStyle="WeChat">微信授权登录{{ scene }}</up-button>
  15. <view class="xieyi text-center">
  16. <up-checkbox-group v-model="checkboxValue">
  17. <up-checkbox label="我已认真阅读、理解并同意" name="agree" usedAlone @change="onCheckboxChange" class="text-grey1">
  18. </up-checkbox>
  19. </up-checkbox-group>
  20. <!-- 备用方案:使用原生checkbox -->
  21. <!-- <checkbox :checked="checkboxValue.value" @change="onNativeChange" style="transform:scale(0.7)" />
  22. <text class="text-grey1">我已认真阅读、理解并同意</text> -->
  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' // Path to the logo image (red tree)
  39. // 获取全局配置
  40. // const globalConfig = getApp().globalData.config;
  41. const loginForm = reactive({
  42. username: '',
  43. password: '',
  44. code: '',
  45. uuid: '',
  46. referrerType: '',
  47. referrerId: '',
  48. })
  49. const checkboxValue = ref(false)
  50. const globalData = ref({
  51. statusBarHeight: 47,
  52. navBarHeight: 91,
  53. })
  54. // const codeUrl = ref(""); // Not used in the new design
  55. // const captchaEnabled = ref(true); // Not used in the new design
  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 onLogin = () => {
  115. uni.$u.debounce(handleLogin, 300)
  116. }
  117. const handleLogin = async () => {
  118. if (!checkboxValue.value) {
  119. uni.showToast({
  120. title: '请先阅读并同意相关协议',
  121. icon: 'none',
  122. })
  123. return
  124. }
  125. uni.showLoading({
  126. title: '登录中,请耐心等待...',
  127. }) // 使用uni-app的loading方法替代$modal.loading
  128. // 获取code
  129. uni.login({
  130. provider: 'weixin',
  131. success: (res) => {
  132. if (res.code == 500) {
  133. uni.showLoading({
  134. title: '系统暂未开发,敬请期待',
  135. })
  136. } else if (res.code == 400) {
  137. uni.showLoading({
  138. title: '系统暂未开放',
  139. })
  140. }
  141. loginForm.code = res.code
  142. pwdLogin()
  143. uni.hideLoading()
  144. },
  145. })
  146. }
  147. // 密码登录
  148. const pwdLogin = async () => {
  149. if (!store) {
  150. console.error('Store is not defined')
  151. return
  152. }
  153. store.dispatch('Login', loginForm).then(() => {
  154. loginSuccess()
  155. })
  156. }
  157. // 登录成功后,处理函数
  158. const loginSuccess = () => {
  159. store.dispatch('GetInfo').then((res) => {
  160. uni.setStorageSync('userType', store.state.user.userOrWorker)
  161. uni.setStorageSync('userId', res.user.userId)
  162. userOrWorker({ userType: store.state.user.userOrWorker })
  163. .then(res => {
  164. uni.switchTab({
  165. url: '/pages/index',
  166. })
  167. })
  168. .catch(err => {
  169. console.error('设置失败:', err);
  170. });
  171. })
  172. }
  173. // 获取胶囊位置信息
  174. const getSystemInfo = () => {
  175. uni.getSystemInfo({
  176. success: (res) => {
  177. const statusBarHeight = res.statusBarHeight
  178. const navBarHeight =
  179. (res.platform === 'android') ? 48 : 44 + res.statusBarHeight
  180. globalData.value = { statusBarHeight, navBarHeight }
  181. },
  182. })
  183. }
  184. onShow(() => {
  185. getSystemInfo()
  186. })
  187. // 页面加载时
  188. onMounted(() => {
  189. uni.setStorageSync('userType', 0)
  190. // 设置状态栏为透明
  191. uni.setNavigationBarColor({
  192. frontColor: '#ffffff',
  193. backgroundColor: 'rgba(0,0,0,0)',
  194. animation: {
  195. duration: 0,
  196. timingFunc: 'easeIn',
  197. },
  198. })
  199. getSystemInfo()
  200. })
  201. const onCheckboxChange = (value) => {
  202. console.log('复选框状态改变:', value)
  203. checkboxValue.value = value
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .normal-login-container {
  208. // border: 2px solid red;
  209. width: 100vw;
  210. height: 100vh;
  211. // width: 100vw;
  212. // height: 100vh;
  213. border-radius: 48rpx;
  214. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  215. position: relative;
  216. overflow-x: hidden;
  217. .wave-img {
  218. position: absolute;
  219. top: 0;
  220. left: 0;
  221. width: 100vw;
  222. height: 100vh;
  223. }
  224. display: flex;
  225. flex-direction: column;
  226. align-items: center;
  227. }
  228. .logo-content {
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. position: relative;
  233. z-index: 1;
  234. .logo-image {
  235. width: 232rpx;
  236. height: 201rpx;
  237. margin-top: 47rpx;
  238. margin-bottom: -10rpx;
  239. margin-right: 300rpx;
  240. margin-left: 300rpx;
  241. }
  242. .title {
  243. width: 360rpx;
  244. height: 128rpx;
  245. font-family: Poppins;
  246. font-size: 90rpx;
  247. font-weight: 600;
  248. line-height: 127.81rpx;
  249. letter-spacing: normal;
  250. color: #FFFFFF;
  251. z-index: 1;
  252. margin-top: 0;
  253. margin-bottom: 82rpx;
  254. margin-right: 195rpx;
  255. margin-left: 195rpx;
  256. }
  257. }
  258. .house-illustration {
  259. width: 720rpx;
  260. height: 334rpx;
  261. margin-top: 0;
  262. margin-bottom: 78rpx;
  263. margin-right: 136rpx;
  264. margin-left: 136rpx;
  265. }
  266. .slogan-content {
  267. margin-top: 0;
  268. margin-bottom: 235rpx;
  269. margin-right: 300rpx;
  270. margin-left: 300rpx;
  271. z-index: 1;
  272. .slogan-text {
  273. display: flex;
  274. flex-direction: column;
  275. align-items: center;
  276. width: 448rpx;
  277. height: 52rpx;
  278. font-family: Poppins;
  279. font-size: 32rpx;
  280. font-weight: 600;
  281. line-height: 52rpx;
  282. text-align: center;
  283. letter-spacing: normal;
  284. color: #824727;
  285. }
  286. }
  287. .actions-container {
  288. display: flex;
  289. flex-direction: column;
  290. align-items: center;
  291. width: 100%;
  292. z-index: 1;
  293. }
  294. .xieyi {
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. flex-wrap: wrap;
  299. }
  300. .text-blue {
  301. color: #1976d2;
  302. margin: 0 4rpx;
  303. }
  304. .text-grey1 {
  305. color: #333333;
  306. }
  307. .text-center {
  308. text-align: center;
  309. }
  310. </style>