login.vue 8.3 KB

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