login.vue 7.7 KB

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