login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 } 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: 1,
  63. referrerId: 111,
  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. // 用户注册 - assuming this might be needed later, keeping it
  74. const handleUserRegister = () => {
  75. router.push('/pages/register') // 替换为实际的路由跳转逻辑
  76. }
  77. const WeChat = {
  78. width: '530rpx',
  79. height: '96rpx',
  80. opacity: 1,
  81. background: '#8B4F2D',
  82. color: '#FFFFFF',
  83. borderRadius: '48rpx',
  84. fontWeight: '700px',
  85. fontSize: '32rpx',
  86. marginLeft: 'auto',
  87. marginRight: 'auto',
  88. marginBottom: '10rpx',
  89. display: 'flex',
  90. justifyContent: 'center',
  91. alignItems: 'center',
  92. border: 'none',
  93. boxShadow: 'none',
  94. }
  95. // 隐私协议
  96. const handlePrivacy = () => {
  97. uni.navigateTo({
  98. url: '/pages_home/pages/login/index',
  99. })
  100. }
  101. // 用户协议
  102. const handleUserAgrement = () => {
  103. uni.navigateTo({
  104. url: '/pages_home/pages/login/user',
  105. })
  106. }
  107. // 登录方法
  108. const handleLogin = async () => {
  109. console.log('checkboxValue', checkboxValue.value)
  110. if (!checkboxValue.value) {
  111. uni.showToast({
  112. title: '请先阅读并同意相关协议',
  113. icon: 'none',
  114. })
  115. return
  116. }
  117. uni.showLoading({
  118. title: '登录中,请耐心等待...',
  119. }) // 使用uni-app的loading方法替代$modal.loading
  120. // 获取服务商信息
  121. uni.getProvider({
  122. service: 'oauth',
  123. success: (res) => {
  124. console.log(res)
  125. },
  126. })
  127. // 获取code
  128. uni.login({
  129. provider: 'weixin',
  130. success: (res) => {
  131. if (res.code == 500) {
  132. uni.showLoading({
  133. title: '系统暂未开发,敬请期待',
  134. })
  135. } else if (res.code == 400) {
  136. uni.showLoading({
  137. title: '系统暂未开放',
  138. })
  139. }
  140. // 保持原有的 referrerType 和 referrerId
  141. const currentReferrerType = loginForm.referrerType
  142. const currentReferrerId = loginForm.referrerId
  143. loginForm.code = res.code
  144. // 确保 referrerType 和 referrerId 不被覆盖
  145. loginForm.referrerType = currentReferrerType
  146. loginForm.referrerId = currentReferrerId
  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. // if (store.state.user.userOrWorker == 0) {
  175. // uni.reLaunch({
  176. // url: '/pages/UserSelection',
  177. // })
  178. // return
  179. // }
  180. uni.setStorageSync('userType', store.state.user.userOrWorker)
  181. uni.setStorageSync('userId', res.user.userId)
  182. uni.switchTab({
  183. url: '/pages/index',
  184. })
  185. })
  186. }
  187. // 获取胶囊位置信息
  188. const getSystemInfo = () => {
  189. uni.getSystemInfo({
  190. success: (res) => {
  191. const statusBarHeight = res.statusBarHeight
  192. const navBarHeight =
  193. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  194. globalData.value = { statusBarHeight, navBarHeight }
  195. },
  196. })
  197. }
  198. onShow(() => {
  199. getSystemInfo()
  200. })
  201. // 页面加载时
  202. onMounted(() => {
  203. uni.setStorageSync('userType', 0)
  204. // 设置状态栏为透明
  205. uni.setNavigationBarColor({
  206. frontColor: '#ffffff',
  207. backgroundColor: 'rgba(0,0,0,0)',
  208. animation: {
  209. duration: 0,
  210. timingFunc: 'easeIn',
  211. },
  212. })
  213. getSystemInfo()
  214. })
  215. const onCheckboxChange = (value) => {
  216. console.log('复选框状态改变:', value)
  217. checkboxValue.value = value
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .normal-login-container {
  222. // border: 2px solid red;
  223. width: 100vw;
  224. height: 100vh;
  225. // width: 100vw;
  226. // height: 100vh;
  227. border-radius: 48rpx;
  228. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  229. position: relative;
  230. overflow-x: hidden;
  231. .wave-img {
  232. position: absolute;
  233. top: 0;
  234. left: 0;
  235. width: 100vw;
  236. height: 100vh;
  237. }
  238. display: flex;
  239. flex-direction: column;
  240. align-items: center;
  241. }
  242. .logo-content {
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. position: relative;
  247. z-index: 1;
  248. .logo-image {
  249. width: 90px;
  250. height: 78px;
  251. margin-top: 47rpx;
  252. margin-bottom: -10rpx;
  253. margin-right: 300rpx;
  254. margin-left: 300rpx;
  255. }
  256. .title {
  257. width: 184rpx;
  258. height: 60rpx;
  259. font-family: Poppins;
  260. font-size: 46rpx;
  261. font-weight: 400;
  262. line-height: 60rpx;
  263. letter-spacing: normal;
  264. color: #ffffff;
  265. z-index: 1;
  266. margin-top: 0;
  267. margin-bottom: 77rpx;
  268. margin-right: 300rpx;
  269. margin-left: 300rpx;
  270. }
  271. }
  272. .house-illustration {
  273. width: 720rpx;
  274. height: 334rpx;
  275. margin-top: 0;
  276. margin-bottom: 50rpx;
  277. margin-right: 136rpx;
  278. margin-left: 136rpx;
  279. }
  280. .slogan-content {
  281. margin-top: 0;
  282. margin-bottom: 380rpx;
  283. margin-right: 300rpx;
  284. margin-left: 300rpx;
  285. z-index: 1;
  286. .slogan-text {
  287. display: flex;
  288. flex-direction: column;
  289. align-items: center;
  290. width: 448rpx;
  291. height: 52rpx;
  292. font-family: Poppins;
  293. font-size: 32rpx;
  294. font-weight: 600;
  295. line-height: 52rpx;
  296. text-align: center;
  297. letter-spacing: normal;
  298. color: #824727;
  299. }
  300. }
  301. .actions-container {
  302. display: flex;
  303. flex-direction: column;
  304. align-items: center;
  305. width: 100%;
  306. z-index: 1;
  307. }
  308. .xieyi {
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. flex-wrap: wrap;
  313. }
  314. .text-blue {
  315. color: #1976d2;
  316. margin: 0 4rpx;
  317. }
  318. .text-grey1 {
  319. color: #333333;
  320. }
  321. .text-center {
  322. text-align: center;
  323. }
  324. </style>