login.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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(store.state.user.userOrWorker, '>>>>99')
  164. // if (store.state.user.userOrWorker == 0) {
  165. // uni.reLaunch({
  166. // url: '/pages/UserSelection',
  167. // })
  168. // return
  169. // }
  170. uni.setStorageSync('userType', store.state.user.userOrWorker)
  171. uni.switchTab({
  172. url: '/pages/index',
  173. })
  174. })
  175. }
  176. // 获取胶囊位置信息
  177. const getSystemInfo = () => {
  178. uni.getSystemInfo({
  179. success: (res) => {
  180. const statusBarHeight = res.statusBarHeight
  181. const navBarHeight =
  182. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  183. globalData.value = { statusBarHeight, navBarHeight }
  184. },
  185. })
  186. }
  187. onShow(() => {
  188. getSystemInfo()
  189. })
  190. // 页面加载时
  191. onMounted(() => {
  192. uni.setStorageSync('userType', 0)
  193. // 设置状态栏为透明
  194. uni.setNavigationBarColor({
  195. frontColor: '#ffffff',
  196. backgroundColor: 'rgba(0,0,0,0)',
  197. animation: {
  198. duration: 0,
  199. timingFunc: 'easeIn',
  200. },
  201. })
  202. getSystemInfo()
  203. })
  204. const onCheckboxChange = (value) => {
  205. console.log('复选框状态改变:', value)
  206. checkboxValue.value = value
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .normal-login-container {
  211. // border: 2px solid red;
  212. width: 100vw;
  213. height: 100vh;
  214. // width: 100vw;
  215. // height: 100vh;
  216. border-radius: 48rpx;
  217. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  218. position: relative;
  219. overflow-x: hidden;
  220. .wave-img {
  221. position: absolute;
  222. top: 0;
  223. left: 0;
  224. width: 100vw;
  225. height: 100vh;
  226. }
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. }
  231. .logo-content {
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. position: relative;
  236. z-index: 1;
  237. .logo-image {
  238. width: 90px;
  239. height: 78px;
  240. margin-top: 47rpx;
  241. margin-bottom: -10rpx;
  242. margin-right: 300rpx;
  243. margin-left: 300rpx;
  244. }
  245. .title {
  246. width: 184rpx;
  247. height: 60rpx;
  248. font-family: Poppins;
  249. font-size: 46rpx;
  250. font-weight: 400;
  251. line-height: 60rpx;
  252. letter-spacing: normal;
  253. color: #ffffff;
  254. z-index: 1;
  255. margin-top: 0;
  256. margin-bottom: 77rpx;
  257. margin-right: 300rpx;
  258. margin-left: 300rpx;
  259. }
  260. }
  261. .house-illustration {
  262. width: 720rpx;
  263. height: 334rpx;
  264. margin-top: 0;
  265. margin-bottom: 50rpx;
  266. margin-right: 136rpx;
  267. margin-left: 136rpx;
  268. }
  269. .slogan-content {
  270. margin-top: 0;
  271. margin-bottom: 380rpx;
  272. margin-right: 300rpx;
  273. margin-left: 300rpx;
  274. z-index: 1;
  275. .slogan-text {
  276. display: flex;
  277. flex-direction: column;
  278. align-items: center;
  279. width: 448rpx;
  280. height: 52rpx;
  281. font-family: Poppins;
  282. font-size: 32rpx;
  283. font-weight: 600;
  284. line-height: 52rpx;
  285. text-align: center;
  286. letter-spacing: normal;
  287. color: #824727;
  288. }
  289. }
  290. .actions-container {
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. width: 100%;
  295. z-index: 1;
  296. }
  297. .xieyi {
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. flex-wrap: wrap;
  302. }
  303. .text-blue {
  304. color: #1976d2;
  305. margin: 0 4rpx;
  306. }
  307. .text-grey1 {
  308. color: #333333;
  309. }
  310. .text-center {
  311. text-align: center;
  312. }
  313. </style>