login.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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">微信授权登录</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. const imagePath = '/static/9efd1.png' // Path to the logo image (red tree)
  38. // 获取全局配置
  39. // const globalConfig = getApp().globalData.config;
  40. const loginForm = reactive({
  41. username: '',
  42. password: '',
  43. code: '',
  44. uuid: '',
  45. referrerType: '',
  46. referrerId: '',
  47. })
  48. const checkboxValue = ref(false)
  49. const globalData = ref({
  50. statusBarHeight: 47,
  51. navBarHeight: 91,
  52. })
  53. // const codeUrl = ref(""); // Not used in the new design
  54. // const captchaEnabled = ref(true); // Not used in the new design
  55. const router = useRouter()
  56. // 获取小程序码参数
  57. onLoad((options) => {
  58. console.log('onLoad options:', options)
  59. // 处理从二维码扫描进入的场景
  60. if (options.scene) {
  61. const scene = decodeURIComponent(options.scene)
  62. const params = scene.split(':')
  63. if (params.length >= 2) {
  64. loginForm.referrerType = params[0]
  65. loginForm.referrerId = params[1]
  66. console.log('从二维码获取参数:', loginForm.referrerType, loginForm.referrerId)
  67. }
  68. }
  69. // 如果有直接传入的参数也可以获取
  70. if (options.referrerType) {
  71. loginForm.referrerType = options.referrerType
  72. }
  73. if (options.referrerId) {
  74. loginForm.referrerId = options.referrerId
  75. }
  76. })
  77. // 用户注册 - assuming this might be needed later, keeping it
  78. const handleUserRegister = () => {
  79. router.push('/pages/register') // 替换为实际的路由跳转逻辑
  80. }
  81. const WeChat = {
  82. width: '530rpx',
  83. height: '96rpx',
  84. opacity: 1,
  85. background: '#8B4F2D',
  86. color: '#FFFFFF',
  87. borderRadius: '48rpx',
  88. fontWeight: '700px',
  89. fontSize: '32rpx',
  90. marginLeft: 'auto',
  91. marginRight: 'auto',
  92. marginBottom: '10rpx',
  93. display: 'flex',
  94. justifyContent: 'center',
  95. alignItems: 'center',
  96. border: 'none',
  97. boxShadow: 'none',
  98. }
  99. // 隐私协议
  100. const handlePrivacy = () => {
  101. uni.navigateTo({
  102. url: '/pages_home/pages/login/index',
  103. })
  104. }
  105. // 用户协议
  106. const handleUserAgrement = () => {
  107. uni.navigateTo({
  108. url: '/pages_home/pages/login/user',
  109. })
  110. }
  111. // 登录方法
  112. const onLogin = () => {
  113. uni.$u.debounce(handleLogin, 300)
  114. }
  115. const handleLogin = async () => {
  116. if (!checkboxValue.value) {
  117. uni.showToast({
  118. title: '请先阅读并同意相关协议',
  119. icon: 'none',
  120. })
  121. return
  122. }
  123. uni.showLoading({
  124. title: '登录中,请耐心等待...',
  125. }) // 使用uni-app的loading方法替代$modal.loading
  126. // 获取code
  127. uni.login({
  128. provider: 'weixin',
  129. success: (res) => {
  130. if (res.code == 500) {
  131. uni.showLoading({
  132. title: '系统暂未开发,敬请期待',
  133. })
  134. } else if (res.code == 400) {
  135. uni.showLoading({
  136. title: '系统暂未开放',
  137. })
  138. }
  139. loginForm.code = res.code
  140. pwdLogin()
  141. uni.hideLoading()
  142. },
  143. })
  144. }
  145. // 密码登录
  146. const pwdLogin = async () => {
  147. if (!store) {
  148. console.error('Store is not defined')
  149. return
  150. }
  151. store.dispatch('Login', loginForm).then(() => {
  152. loginSuccess()
  153. })
  154. }
  155. // 登录成功后,处理函数
  156. const loginSuccess = () => {
  157. store.dispatch('GetInfo').then((res) => {
  158. uni.setStorageSync('userType', store.state.user.userOrWorker)
  159. uni.setStorageSync('userId', res.user.userId)
  160. userOrWorker({ userType: store.state.user.userOrWorker })
  161. .then(res => {
  162. uni.switchTab({
  163. url: '/pages/index',
  164. })
  165. })
  166. .catch(err => {
  167. console.error('设置失败:', err);
  168. });
  169. })
  170. }
  171. // 获取胶囊位置信息
  172. const getSystemInfo = () => {
  173. uni.getSystemInfo({
  174. success: (res) => {
  175. const statusBarHeight = res.statusBarHeight
  176. const navBarHeight =
  177. (res.platform === 'android') ? 48 : 44 + res.statusBarHeight
  178. globalData.value = { statusBarHeight, navBarHeight }
  179. },
  180. })
  181. }
  182. onShow(() => {
  183. getSystemInfo()
  184. })
  185. // 页面加载时
  186. onMounted(() => {
  187. uni.setStorageSync('userType', 0)
  188. // 设置状态栏为透明
  189. uni.setNavigationBarColor({
  190. frontColor: '#ffffff',
  191. backgroundColor: 'rgba(0,0,0,0)',
  192. animation: {
  193. duration: 0,
  194. timingFunc: 'easeIn',
  195. },
  196. })
  197. getSystemInfo()
  198. })
  199. const onCheckboxChange = (value) => {
  200. console.log('复选框状态改变:', value)
  201. checkboxValue.value = value
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .normal-login-container {
  206. // border: 2px solid red;
  207. width: 100vw;
  208. height: 100vh;
  209. // width: 100vw;
  210. // height: 100vh;
  211. border-radius: 48rpx;
  212. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  213. position: relative;
  214. overflow-x: hidden;
  215. .wave-img {
  216. position: absolute;
  217. top: 0;
  218. left: 0;
  219. width: 100vw;
  220. height: 100vh;
  221. }
  222. display: flex;
  223. flex-direction: column;
  224. align-items: center;
  225. }
  226. .logo-content {
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. position: relative;
  231. z-index: 1;
  232. .logo-image {
  233. width: 232rpx;
  234. height: 201rpx;
  235. margin-top: 47rpx;
  236. margin-bottom: -10rpx;
  237. margin-right: 300rpx;
  238. margin-left: 300rpx;
  239. }
  240. .title {
  241. width: 360rpx;
  242. height: 128rpx;
  243. font-family: Poppins;
  244. font-size: 90rpx;
  245. font-weight: 600;
  246. line-height: 127.81rpx;
  247. letter-spacing: normal;
  248. color: #FFFFFF;
  249. z-index: 1;
  250. margin-top: 0;
  251. margin-bottom: 82rpx;
  252. margin-right: 195rpx;
  253. margin-left: 195rpx;
  254. }
  255. }
  256. .house-illustration {
  257. width: 720rpx;
  258. height: 334rpx;
  259. margin-top: 0;
  260. margin-bottom: 78rpx;
  261. margin-right: 136rpx;
  262. margin-left: 136rpx;
  263. }
  264. .slogan-content {
  265. margin-top: 0;
  266. margin-bottom: 235rpx;
  267. margin-right: 300rpx;
  268. margin-left: 300rpx;
  269. z-index: 1;
  270. .slogan-text {
  271. display: flex;
  272. flex-direction: column;
  273. align-items: center;
  274. width: 448rpx;
  275. height: 52rpx;
  276. font-family: Poppins;
  277. font-size: 32rpx;
  278. font-weight: 600;
  279. line-height: 52rpx;
  280. text-align: center;
  281. letter-spacing: normal;
  282. color: #824727;
  283. }
  284. }
  285. .actions-container {
  286. display: flex;
  287. flex-direction: column;
  288. align-items: center;
  289. width: 100%;
  290. z-index: 1;
  291. }
  292. .xieyi {
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. flex-wrap: wrap;
  297. }
  298. .text-blue {
  299. color: #1976d2;
  300. margin: 0 4rpx;
  301. }
  302. .text-grey1 {
  303. color: #333333;
  304. }
  305. .text-center {
  306. text-align: center;
  307. }
  308. </style>