login.vue 7.9 KB

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