login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix" /> -->
  5. <image :src="imagePath" mode="aspectFit" style="width: 100rpx;height: 100rpx;"></image>
  6. <text class="title">乐融融</text>
  7. </view>
  8. <!-- <view class="login-form-content">
  9. <view class="action-btn">
  10. <button @click="handleLogin" class="login-btn cu-btn block bg-green lg round">微信授权登录</button>
  11. </view>
  12. <view class="reg text-center" v-if="register">
  13. <text class="text-grey1">没有账号?</text>
  14. <text @click="handleUserRegister" class="text-blue">立即注册</text>
  15. </view>
  16. <view class="xieyi text-center">
  17. <text class="text-grey1">登录即代表同意</text>
  18. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  19. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  20. </view>
  21. </view> -->
  22. <view>
  23. </view>
  24. <up-popup :show="show" mode="bottom" @close="close" @open="open">
  25. <view class="popup-content">
  26. <!-- 上方头像 -->
  27. <up-avatar :src="src" class="avatar"></up-avatar>
  28. <!-- 下方按钮 -->
  29. <up-button type="success" shape="circle" class="button" @click="handleLogin">获取微信授权登录</up-button>
  30. </view>
  31. <view class="xieyi text-center">
  32. <text class="text-grey1">登录即代表同意</text>
  33. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  34. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  35. </view>
  36. </up-popup>
  37. </view>
  38. </template>
  39. <script setup>
  40. import {
  41. ref,
  42. reactive,
  43. onMounted
  44. } from 'vue';
  45. import {
  46. useRouter,
  47. useRoute
  48. } from 'vue-router'; // 根据实际情况选择路由库
  49. import {
  50. getCodeImg,
  51. login
  52. } from '@/api/login';
  53. import store from "@/store"
  54. const imagePath = '/static/logo.png';
  55. // 获取全局配置
  56. // const globalConfig = getApp().globalData.config; // 注意:getApp()是特定于小程序的方法
  57. const register = ref(false); // 用户注册开关
  58. const loginForm = reactive({
  59. username: "admin",
  60. password: "admin123",
  61. code: "",
  62. uuid: ''
  63. });
  64. const codeUrl = ref("");
  65. const captchaEnabled = ref(true);
  66. const router = useRouter();
  67. // 创建响应式数据
  68. const show = ref(false);
  69. // 定义方法
  70. function open() {
  71. // 打开逻辑,比如设置 show 为 true
  72. show.value = true;
  73. }
  74. function close() {
  75. // 关闭逻辑,设置 show 为 false
  76. show.value = false;
  77. }
  78. // 获取图形验证码
  79. // const getCode = () => {
  80. // getCodeImg().then(res => {
  81. // captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  82. // if (captchaEnabled.value) {
  83. // codeUrl.value = 'data:image/gif;base64,' + res.img;
  84. // loginForm.uuid = res.uuid;
  85. // }
  86. // });
  87. // };
  88. // 用户注册
  89. const handleUserRegister = () => {
  90. router.push('/pages/register'); // 替换为实际的路由跳转逻辑
  91. };
  92. // 隐私协议
  93. const handlePrivacy = () => {
  94. // let site = globalConfig.appInfo.agreements[0];
  95. router.push(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  96. };
  97. // 用户协议
  98. const handleUserAgrement = () => {
  99. // let site = globalConfig.appInfo.agreements[1];
  100. router.push(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  101. };
  102. // 登录方法
  103. const handleLogin = async () => {
  104. uni.showLoading({
  105. title: "登录中,请耐心等待..."
  106. }); // 使用uni-app的loading方法替代$modal.loading
  107. // 获取服务商信息
  108. uni.getProvider({
  109. service: "oauth",
  110. success: (res) => {
  111. console.log(res);
  112. }
  113. });
  114. // 获取code
  115. uni.login({
  116. provider: 'weixin',
  117. success: (res) => {
  118. loginForm.code = res.code;
  119. // 获取用户信息
  120. uni.getUserInfo({
  121. success: (res) => {
  122. console.log("用户信息", res);
  123. }
  124. });
  125. pwdLogin();
  126. uni.hideLoading()
  127. },
  128. });
  129. };
  130. // 密码登录
  131. const pwdLogin = async () => {
  132. console.log('>>>>>>>234568');
  133. if (!store) {
  134. console.error("Store is not defined");
  135. return;
  136. }
  137. store.dispatch('Login', loginForm).then(() => {
  138. // uni.hideLoading(); // 关闭加载提示
  139. loginSuccess();
  140. })
  141. };
  142. // 登录成功后,处理函数
  143. const loginSuccess = () => {
  144. // 设置用户信息
  145. store.dispatch('GetInfo').then(() => {
  146. router.replace('/pages/index');
  147. });
  148. };
  149. // 页面加载时获取验证码
  150. onMounted(() => {
  151. // getCode();
  152. open();
  153. });
  154. </script>
  155. <style lang="scss">
  156. page {
  157. background-color: #ffffff;
  158. }
  159. .normal-login-container {
  160. width: 100%;
  161. .logo-content {
  162. width: 100%;
  163. font-size: 21px;
  164. text-align: center;
  165. padding-top: 15%;
  166. image {
  167. border-radius: 4px;
  168. }
  169. .title {
  170. margin-left: 10px;
  171. }
  172. }
  173. .login-form-content {
  174. text-align: center;
  175. margin: 20px auto;
  176. margin-top: 15%;
  177. width: 80%;
  178. .input-item {
  179. margin: 20px auto;
  180. background-color: #f5f6f7;
  181. height: 45px;
  182. border-radius: 20px;
  183. .icon {
  184. font-size: 38rpx;
  185. margin-left: 10px;
  186. color: #999;
  187. }
  188. .input {
  189. width: 100%;
  190. font-size: 14px;
  191. line-height: 20px;
  192. text-align: left;
  193. padding-left: 15px;
  194. }
  195. }
  196. .login-btn {
  197. margin-top: 40px;
  198. height: 45px;
  199. }
  200. .reg {
  201. margin-top: 15px;
  202. }
  203. .xieyi {
  204. color: #333;
  205. margin-top: 20px;
  206. }
  207. .login-code {
  208. height: 38px;
  209. float: right;
  210. .login-code-img {
  211. height: 38px;
  212. position: absolute;
  213. margin-left: 10px;
  214. width: 200rpx;
  215. }
  216. }
  217. }
  218. }
  219. /* 弹性容器:垂直方向排列 */
  220. .popup-content {
  221. display: flex;
  222. flex-direction: column;
  223. /* 上下布局 */
  224. align-items: center;
  225. /* 水平居中 */
  226. padding: 30rpx;
  227. gap: 30rpx;
  228. /* 元素间距 */
  229. }
  230. /* 头像样式 */
  231. .avatar {
  232. width: 120rpx;
  233. height: 160rpx;
  234. }
  235. /* 按钮样式 */
  236. .button {
  237. width: 170rpx !important;
  238. /* 覆盖默认宽度 */
  239. margin-left: 0 !important;
  240. /* 清除原代码中的 margin-left */
  241. }
  242. </style>