├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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>
  6. <text class="title">哎呀电子小说</text>
  7. </view>
  8. <view class="login-form-content">
  9. <!-- 用户名密码登录 -->
  10. <view class="input-item flex align-center">
  11. <view class="iconfont icon-user icon"></view>
  12. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  13. </view>
  14. <view class="input-item flex align-center">
  15. <view class="iconfont icon-password icon"></view>
  16. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  17. </view>
  18. <!-- 修复验证码显示 -->
  19. <view class="input-item flex align-center" v-if="captchaEnabled">
  20. <view class="iconfont icon-code icon"></view>
  21. <input v-model="loginForm.code" type="text" class="input" placeholder="请输入验证码" maxlength="4" />
  22. <view class="login-code">
  23. <image :src="codeUrl" @click="getCode" class="login-code-img" mode="widthFix"></image>
  24. </view>
  25. </view>
  26. <view class="action-btn">
  27. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">账号登录</button>
  28. </view>
  29. <view class="reg text-center" v-if="register">
  30. <text class="text-grey1">没有账号?</text>
  31. <text @click="handleUserRegister" class="text-blue">立即注册</text>
  32. </view>
  33. <view class="xieyi text-center">
  34. <text class="text-grey1">登录即代表同意</text>
  35. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  36. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { getCodeImg, login } from '@/api/login'
  43. import { setToken } from '@/utils/auth'
  44. export default {
  45. data() {
  46. return {
  47. codeUrl: "",
  48. captchaEnabled: true,
  49. register: true,
  50. globalConfig: {
  51. appInfo: {
  52. logo: '/static/logo.png',
  53. agreements: []
  54. }
  55. },
  56. loginForm: {
  57. username: "",
  58. password: "",
  59. code: "",
  60. uuid: ''
  61. }
  62. }
  63. },
  64. onLoad(options) {
  65. console.log('登录页面参数:', options)
  66. this.redirectUrl = options.redirect || ''
  67. this.safeInitConfig()
  68. this.getCode()
  69. },
  70. methods: {
  71. // 安全初始化配置
  72. safeInitConfig() {
  73. try {
  74. const app = getApp()
  75. if (app && app.globalData && app.globalData.config) {
  76. this.globalConfig = app.globalData.config
  77. }
  78. } catch (error) {
  79. console.warn('获取全局配置失败:', error)
  80. }
  81. },
  82. // 获取图形验证码
  83. async getCode() {
  84. try {
  85. const res = await getCodeImg()
  86. console.log('验证码响应:', res)
  87. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  88. if (this.captchaEnabled) {
  89. this.codeUrl = 'data:image/gif;base64,' + res.img
  90. this.loginForm.uuid = res.uuid
  91. console.log('验证码URL设置成功')
  92. }
  93. } catch (error) {
  94. console.error('获取验证码失败:', error)
  95. this.captchaEnabled = false
  96. this.$modal.msgError("验证码加载失败")
  97. }
  98. },
  99. // 登录方法 - 简化版
  100. async handleLogin() {
  101. if (!this.loginForm.username) {
  102. this.$modal.msgError("请输入您的账号")
  103. return
  104. }
  105. if (!this.loginForm.password) {
  106. this.$modal.msgError("请输入您的密码")
  107. return
  108. }
  109. if (this.captchaEnabled && !this.loginForm.code) {
  110. this.$modal.msgError("请输入验证码")
  111. return
  112. }
  113. this.$modal.loading("登录中,请耐心等待...")
  114. try {
  115. // 直接调用登录API
  116. const res = await login(
  117. this.loginForm.username,
  118. this.loginForm.password,
  119. this.loginForm.code,
  120. this.loginForm.uuid
  121. )
  122. console.log('登录响应:', res)
  123. if (res.code === 200 && res.token) {
  124. // 存储token
  125. setToken(res.token)
  126. this.$modal.msgSuccess("登录成功")
  127. // 触发全局登录状态更新
  128. uni.$emit('loginStatusUpdate', { isLoggedIn: true })
  129. // 跳转逻辑
  130. setTimeout(() => {
  131. this.loginSuccess()
  132. }, 1000)
  133. } else {
  134. this.$modal.msgError(res.msg || '登录失败')
  135. if (this.captchaEnabled) {
  136. this.getCode()
  137. }
  138. }
  139. } catch (error) {
  140. console.error('登录失败:', error)
  141. this.$modal.msgError(error.msg || '登录失败,请重试')
  142. if (this.captchaEnabled) {
  143. this.getCode()
  144. }
  145. } finally {
  146. this.$modal.closeLoading()
  147. }
  148. },
  149. // 登录成功处理
  150. loginSuccess() {
  151. console.log('登录成功,准备跳转')
  152. // 如果有重定向URL,跳转到指定页面
  153. if (this.redirectUrl) {
  154. console.log('跳转到重定向页面:', this.redirectUrl)
  155. uni.redirectTo({
  156. url: this.redirectUrl
  157. })
  158. } else {
  159. // 默认跳转到首页
  160. console.log('跳转到首页')
  161. uni.switchTab({
  162. url: '/pages/index/index'
  163. })
  164. }
  165. },
  166. // 其他方法保持不变
  167. handleUserRegister() {
  168. uni.navigateTo({
  169. url: '/pages/register/index'
  170. })
  171. },
  172. handlePrivacy() {
  173. const site = this.globalConfig.appInfo.agreements[0] || { title: '隐私协议', url: '' }
  174. uni.navigateTo({
  175. url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
  176. })
  177. },
  178. handleUserAgrement() {
  179. const site = this.globalConfig.appInfo.agreements[1] || { title: '用户协议', url: '' }
  180. uni.navigateTo({
  181. url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
  182. })
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss">
  188. page {
  189. background-color: #ffffff;
  190. }
  191. .normal-login-container {
  192. width: 100%;
  193. min-height: 100vh;
  194. padding: 40rpx;
  195. .logo-content {
  196. width: 100%;
  197. font-size: 21px;
  198. text-align: center;
  199. padding-top: 15%;
  200. flex-direction: column;
  201. image {
  202. border-radius: 4px;
  203. }
  204. .title {
  205. margin: 10px 0;
  206. font-size: 24px;
  207. color: #e94f87;
  208. }
  209. }
  210. .login-form-content {
  211. text-align: center;
  212. margin: 20px auto;
  213. margin-top: 10%;
  214. width: 100%;
  215. .input-item {
  216. margin: 20px auto;
  217. background-color: #f5f6f7;
  218. height: 45px;
  219. border-radius: 20px;
  220. display: flex;
  221. align-items: center;
  222. padding: 0 15px;
  223. .icon {
  224. font-size: 20px;
  225. color: #999;
  226. margin-right: 10px;
  227. }
  228. .input {
  229. flex: 1;
  230. font-size: 14px;
  231. line-height: 20px;
  232. text-align: left;
  233. background: transparent;
  234. }
  235. }
  236. .login-btn {
  237. margin-top: 40px;
  238. height: 45px;
  239. background: #e94f87 !important;
  240. color: #fff;
  241. border-radius: 25px;
  242. font-size: 16px;
  243. }
  244. .reg {
  245. margin-top: 15px;
  246. font-size: 14px;
  247. }
  248. .xieyi {
  249. color: #333;
  250. margin-top: 20px;
  251. font-size: 12px;
  252. }
  253. .login-code {
  254. margin-left: 10px;
  255. .login-code-img {
  256. height: 38px;
  257. width: 100px;
  258. border-radius: 4px;
  259. }
  260. }
  261. }
  262. }
  263. </style>