login.vue 8.4 KB

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