├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

login.vue 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <text class="title">哎呀免费小说登录</text>
  5. </view>
  6. <view class="login-form-content">
  7. <view class="input-item flex align-center">
  8. <view class="iconfont icon-user icon"></view>
  9. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  10. </view>
  11. <view class="input-item flex align-center">
  12. <view class="iconfont icon-password icon"></view>
  13. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  14. </view>
  15. <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  16. <view class="iconfont icon-code icon"></view>
  17. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  18. <view class="login-code">
  19. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  20. </view>
  21. </view>
  22. <view class="action-btn">
  23. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  24. </view>
  25. <view class="reg text-center" v-if="register">
  26. <text class="text-grey1">没有账号?</text>
  27. <text @click="handleUserRegister" class="text-blue">立即注册</text>
  28. </view>
  29. <view class="xieyi text-center">
  30. <text class="text-grey1">登录即代表同意</text>
  31. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  32. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  33. </view>
  34. </view>
  35. <view class="reading-tips">
  36. <text class="tip-text">登录后即可:</text>
  37. <view class="benefits">
  38. <text>✓ 继续阅读精彩章节</text>
  39. <text>✓ 加入书架保存进度</text>
  40. <text>✓ 获得每日阅读奖励</text>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. codeUrl: "",
  50. captchaEnabled: false, // 默认不开启验证码
  51. register: false,
  52. // 安全的全局配置访问方式
  53. globalConfig: {
  54. appInfo: {
  55. logo: "",
  56. agreements: []
  57. }
  58. },
  59. loginForm: {
  60. username: "",
  61. password: "",
  62. code: "",
  63. uuid: ""
  64. }
  65. }
  66. },
  67. created() {
  68. // 安全地获取全局配置
  69. this.safeInit();
  70. },
  71. onLoad() {
  72. // 如果全局配置已设置,则使用全局配置
  73. if (this.$config) {
  74. this.globalConfig = this.$config;
  75. }
  76. },
  77. methods: {
  78. // 安全的初始化方法
  79. safeInit() {
  80. try {
  81. // 安全地获取全局配置
  82. if (typeof getApp === 'function') {
  83. const app = getApp();
  84. if (app && app.globalData && app.globalData.config) {
  85. this.globalConfig = app.globalData.config;
  86. }
  87. }
  88. // 尝试获取验证码
  89. this.getCodeSafe();
  90. } catch (error) {
  91. console.error('初始化失败:', error);
  92. }
  93. },
  94. // 安全的获取验证码方法
  95. async getCodeSafe() {
  96. try {
  97. await this.getCode();
  98. } catch (error) {
  99. console.error('获取验证码失败:', error);
  100. // 可以设置默认行为,比如不显示验证码
  101. this.captchaEnabled = false;
  102. }
  103. },
  104. // 获取验证码
  105. async getCode() {
  106. // 确保$http对象可用
  107. if (!this.$http || typeof this.$http.get !== 'function') {
  108. console.warn('$http未定义或不可用');
  109. return;
  110. }
  111. try {
  112. const res = await this.$http.get('/captchaImage');
  113. if (res.code === 200) {
  114. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  115. if (this.captchaEnabled) {
  116. this.codeUrl = 'data:image/png;base64,' + res.data.img;
  117. this.loginForm.uuid = res.data.uuid;
  118. }
  119. } else {
  120. console.error('验证码获取失败:', res.msg);
  121. }
  122. } catch (error) {
  123. console.error('验证码请求失败:', error);
  124. throw error;
  125. }
  126. },
  127. // 用户注册
  128. handleUserRegister() {
  129. this.$router.push('/pages/register');
  130. },
  131. // 隐私协议
  132. handlePrivacy() {
  133. // 简化处理,直接跳转到webview页面
  134. this.$router.push('/pages/common/webview?title=隐私协议&url=https://example.com/privacy');
  135. },
  136. // 用户协议
  137. handleUserAgrement() {
  138. // 简化处理,直接跳转到webview页面
  139. this.$router.push('/pages/common/webview?title=用户协议&url=https://example.com/agreement');
  140. },
  141. // 登录方法
  142. async handleLogin() {
  143. if (!this.loginForm.username) {
  144. this.$modal.msgError("请输入账号");
  145. return;
  146. }
  147. if (!this.loginForm.password) {
  148. this.$modal.msgError("请输入密码");
  149. return;
  150. }
  151. if (this.captchaEnabled && !this.loginForm.code) {
  152. this.$modal.msgError("请输入验证码");
  153. return;
  154. }
  155. this.$modal.loading("登录中,请耐心等待...");
  156. try {
  157. await this.pwdLogin();
  158. } catch (error) {
  159. this.$modal.closeLoading();
  160. this.$modal.msgError(error.message || '登录失败');
  161. // 刷新验证码
  162. if (this.captchaEnabled) {
  163. this.getCodeSafe();
  164. }
  165. }
  166. },
  167. // 密码登录
  168. async pwdLogin() {
  169. try {
  170. // 使用安全的API调用方式
  171. if (this.$store && this.$store.dispatch) {
  172. await this.$store.dispatch('Login', this.loginForm);
  173. this.$modal.closeLoading();
  174. this.loginSuccess();
  175. } else {
  176. throw new Error('存储系统不可用');
  177. }
  178. } catch (error) {
  179. console.error('登录失败:', error);
  180. throw error;
  181. }
  182. },
  183. // 登录成功后,处理函数
  184. loginSuccess() {
  185. // 设置用户信息
  186. if (this.$store && this.$store.dispatch) {
  187. this.$store.dispatch('GetInfo').then(() => {
  188. this.$router.replace('/pages/index');
  189. }).catch(error => {
  190. console.error('获取用户信息失败:', error);
  191. this.$router.replace('/pages/index');
  192. });
  193. } else {
  194. this.$router.replace('/pages/index');
  195. }
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. /* 保持原有样式不变 */
  202. page {
  203. background-color: #ffffff;
  204. }
  205. .reading-tips {
  206. margin-top: 40rpx;
  207. padding: 20rpx;
  208. background-color: #f9f9f9;
  209. border-radius: 10rpx;
  210. }
  211. .tip-text {
  212. font-size: 32rpx;
  213. font-weight: bold;
  214. display: block;
  215. margin-bottom: 20rpx;
  216. }
  217. .benefits text {
  218. display: block;
  219. font-size: 28rpx;
  220. margin: 10rpx 0;
  221. color: #2c3e50;
  222. }
  223. .normal-login-container {
  224. width: 100%;
  225. .logo-content {
  226. width: 100%;
  227. font-size: 21px;
  228. text-align: center;
  229. padding-top: 15%;
  230. .title {
  231. margin-left: 10px;
  232. }
  233. }
  234. .login-form-content {
  235. text-align: center;
  236. margin: 20px auto;
  237. margin-top: 15%;
  238. width: 80%;
  239. .input-item {
  240. margin: 20px auto;
  241. background-color: #f5f6f7;
  242. height: 45px;
  243. border-radius: 20px;
  244. .icon {
  245. font-size: 38rpx;
  246. margin-left: 10px;
  247. color: #999;
  248. }
  249. .input {
  250. width: 100%;
  251. font-size: 14px;
  252. line-height: 20px;
  253. text-align: left;
  254. padding-left: 15px;
  255. }
  256. }
  257. .login-btn {
  258. margin-top: 40px;
  259. height: 45px;
  260. }
  261. .reg {
  262. margin-top: 15px;
  263. }
  264. .xieyi {
  265. color: #333;
  266. margin-top: 20px;
  267. }
  268. .login-code {
  269. height: 38px;
  270. float: right;
  271. .login-code-img {
  272. height: 38px;
  273. position: absolute;
  274. margin-left: 10px;
  275. width: 200rpx;
  276. }
  277. }
  278. }
  279. }
  280. </style>