login.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. const onNativeChange = (e) => {
  209. console.log('原生复选框状态改变:', e.detail.value)
  210. checkboxValue.value = e.detail.value
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .normal-login-container {
  215. // border: 2px solid red;
  216. width: 100vw;
  217. height: 100vh;
  218. // width: 100vw;
  219. // height: 100vh;
  220. border-radius: 48rpx;
  221. background: linear-gradient(156deg, #f5c954 -4%, #f66c44 110%);
  222. position: relative;
  223. overflow-x: hidden;
  224. .wave-img {
  225. position: absolute;
  226. top: 0;
  227. left: 0;
  228. width: 100vw;
  229. height: 100vh;
  230. }
  231. display: flex;
  232. flex-direction: column;
  233. align-items: center;
  234. }
  235. .logo-content {
  236. display: flex;
  237. flex-direction: column;
  238. align-items: center;
  239. position: relative;
  240. z-index: 1;
  241. .logo-image {
  242. width: 90px;
  243. height: 78px;
  244. margin-top: 47rpx;
  245. margin-bottom: -10rpx;
  246. margin-right: 300rpx;
  247. margin-left: 300rpx;
  248. }
  249. .title {
  250. width: 184rpx;
  251. height: 60rpx;
  252. font-family: Poppins;
  253. font-size: 46rpx;
  254. font-weight: 400;
  255. line-height: 60rpx;
  256. letter-spacing: normal;
  257. color: #ffffff;
  258. z-index: 1;
  259. margin-top: 0;
  260. margin-bottom: 77rpx;
  261. margin-right: 300rpx;
  262. margin-left: 300rpx;
  263. }
  264. }
  265. .house-illustration {
  266. width: 720rpx;
  267. height: 334rpx;
  268. margin-top: 0;
  269. margin-bottom: 50rpx;
  270. margin-right: 136rpx;
  271. margin-left: 136rpx;
  272. }
  273. .slogan-content {
  274. margin-top: 0;
  275. margin-bottom: 380rpx;
  276. margin-right: 300rpx;
  277. margin-left: 300rpx;
  278. z-index: 1;
  279. .slogan-text {
  280. display: flex;
  281. flex-direction: column;
  282. align-items: center;
  283. width: 448rpx;
  284. height: 52rpx;
  285. font-family: Poppins;
  286. font-size: 32rpx;
  287. font-weight: 600;
  288. line-height: 52rpx;
  289. text-align: center;
  290. letter-spacing: normal;
  291. color: #824727;
  292. }
  293. }
  294. .actions-container {
  295. display: flex;
  296. flex-direction: column;
  297. align-items: center;
  298. width: 100%;
  299. z-index: 1;
  300. }
  301. .xieyi {
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. flex-wrap: wrap;
  306. }
  307. .text-blue {
  308. color: #1976d2;
  309. margin: 0 4rpx;
  310. }
  311. .text-grey1 {
  312. color: #333333;
  313. }
  314. .text-center {
  315. text-align: center;
  316. }
  317. </style>