login.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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="handleLogin" :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 handleLogin = async () => {
  113. console.log('checkboxValue', checkboxValue.value)
  114. if (!checkboxValue.value) {
  115. uni.showToast({
  116. title: '请先阅读并同意相关协议',
  117. icon: 'none',
  118. })
  119. return
  120. }
  121. uni.showLoading({
  122. title: '登录中,请耐心等待...',
  123. }) // 使用uni-app的loading方法替代$modal.loading
  124. // 获取服务商信息
  125. uni.getProvider({
  126. service: 'oauth',
  127. success: (res) => {
  128. console.log(res)
  129. },
  130. })
  131. // 获取code
  132. uni.login({
  133. provider: 'weixin',
  134. success: (res) => {
  135. if (res.code == 500) {
  136. uni.showLoading({
  137. title: '系统暂未开发,敬请期待',
  138. })
  139. } else if (res.code == 400) {
  140. uni.showLoading({
  141. title: '系统暂未开放',
  142. })
  143. }
  144. loginForm.code = res.code
  145. // 打印当前登录信息
  146. console.log('登录信息:', loginForm)
  147. // 获取用户信息
  148. uni.getUserInfo({
  149. success: (res) => {
  150. console.log('用户信息', res)
  151. },
  152. })
  153. pwdLogin()
  154. uni.hideLoading()
  155. },
  156. })
  157. }
  158. // 密码登录
  159. const pwdLogin = async () => {
  160. if (!store) {
  161. console.error('Store is not defined')
  162. return
  163. }
  164. store.dispatch('Login', loginForm).then(() => {
  165. // uni.hideLoading(); // 关闭加载提示
  166. loginSuccess()
  167. })
  168. }
  169. // 登录成功后,处理函数
  170. const loginSuccess = () => {
  171. store.dispatch('GetInfo').then((res) => {
  172. console.log("TCL: loginSuccess -> res", res)
  173. console.log(store.state.user.userOrWorker, '>>>>99')
  174. uni.setStorageSync('userType', store.state.user.userOrWorker)
  175. uni.setStorageSync('userId', res.user.userId)
  176. userOrWorker({userType: store.state.user.userOrWorker})
  177. .then(res => {
  178. console.log("TCL: loginSuccess -> res", res)
  179. uni.switchTab({
  180. url: '/pages/index',
  181. })
  182. })
  183. .catch(err => {
  184. console.error('设置失败:', err);
  185. });
  186. })
  187. }
  188. // 获取胶囊位置信息
  189. const getSystemInfo = () => {
  190. uni.getSystemInfo({
  191. success: (res) => {
  192. const statusBarHeight = res.statusBarHeight
  193. const navBarHeight =
  194. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  195. globalData.value = { statusBarHeight, navBarHeight }
  196. },
  197. })
  198. }
  199. onShow(() => {
  200. getSystemInfo()
  201. })
  202. // 页面加载时
  203. onMounted(() => {
  204. uni.setStorageSync('userType', 0)
  205. // 设置状态栏为透明
  206. uni.setNavigationBarColor({
  207. frontColor: '#ffffff',
  208. backgroundColor: 'rgba(0,0,0,0)',
  209. animation: {
  210. duration: 0,
  211. timingFunc: 'easeIn',
  212. },
  213. })
  214. getSystemInfo()
  215. })
  216. const onCheckboxChange = (value) => {
  217. console.log('复选框状态改变:', value)
  218. checkboxValue.value = value
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. .normal-login-container {
  223. // border: 2px solid red;
  224. width: 100vw;
  225. height: 100vh;
  226. // width: 100vw;
  227. // height: 100vh;
  228. border-radius: 48rpx;
  229. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  230. position: relative;
  231. overflow-x: hidden;
  232. .wave-img {
  233. position: absolute;
  234. top: 0;
  235. left: 0;
  236. width: 100vw;
  237. height: 100vh;
  238. }
  239. display: flex;
  240. flex-direction: column;
  241. align-items: center;
  242. }
  243. .logo-content {
  244. display: flex;
  245. flex-direction: column;
  246. align-items: center;
  247. position: relative;
  248. z-index: 1;
  249. .logo-image {
  250. width: 232rpx;
  251. height: 201rpx;
  252. margin-top: 47rpx;
  253. margin-bottom: -10rpx;
  254. margin-right: 300rpx;
  255. margin-left: 300rpx;
  256. }
  257. .title {
  258. width: 360rpx;
  259. height: 128rpx;
  260. font-family: Poppins;
  261. font-size: 90rpx;
  262. font-weight: 600;
  263. line-height: 127.81rpx;
  264. letter-spacing: normal;
  265. color: #FFFFFF;
  266. z-index: 1;
  267. margin-top: 0;
  268. margin-bottom: 82rpx;
  269. margin-right: 195rpx;
  270. margin-left: 195rpx;
  271. }
  272. }
  273. .house-illustration {
  274. width: 720rpx;
  275. height: 334rpx;
  276. margin-top: 0;
  277. margin-bottom: 78rpx;
  278. margin-right: 136rpx;
  279. margin-left: 136rpx;
  280. }
  281. .slogan-content {
  282. margin-top: 0;
  283. margin-bottom: 235rpx;
  284. margin-right: 300rpx;
  285. margin-left: 300rpx;
  286. z-index: 1;
  287. .slogan-text {
  288. display: flex;
  289. flex-direction: column;
  290. align-items: center;
  291. width: 448rpx;
  292. height: 52rpx;
  293. font-family: Poppins;
  294. font-size: 32rpx;
  295. font-weight: 600;
  296. line-height: 52rpx;
  297. text-align: center;
  298. letter-spacing: normal;
  299. color: #824727;
  300. }
  301. }
  302. .actions-container {
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. width: 100%;
  307. z-index: 1;
  308. }
  309. .xieyi {
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. flex-wrap: wrap;
  314. }
  315. .text-blue {
  316. color: #1976d2;
  317. margin: 0 4rpx;
  318. }
  319. .text-grey1 {
  320. color: #333333;
  321. }
  322. .text-center {
  323. text-align: center;
  324. }
  325. </style>