login.vue 8.2 KB

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