Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
Expand Down
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TARO_APP_API_BASE_URL=
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text=auto eol=lf

# Keep binary assets untouched.
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ npm-debug.log*

coverage
*.local
.env
.env.*
!.env.example

# Editor directories and files
.vscode/*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ npm run build:weapp
## 🔧 配置说明

### 环境配置
- 修改 `src/utils/request.js` 中的 `BASE_URL` 为实际API地址
- 复制 `.env.example` 为 `.env.local`,并设置 `TARO_APP_API_BASE_URL`
- 调整 `src/utils/constants.js` 中的学期配置

## 贡献指南
Expand Down
33 changes: 33 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
import { defineConfig } from '@tarojs/cli'
import { existsSync, readFileSync } from 'fs'
import { resolve } from 'path'
import { Plugin } from 'vite'
import tailwindcss from 'tailwindcss'
import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'
import devConfig from './dev'
import prodConfig from './prod'

const loadLocalEnv = () => {
const envFiles = ['.env.local', '.env']

envFiles.forEach((fileName) => {
const filePath = resolve(process.cwd(), fileName)
if (!existsSync(filePath)) return

readFileSync(filePath, 'utf8')
.split(/\r?\n/)
.forEach((line) => {
const trimmed = line.trim()
if (!trimmed || trimmed.startsWith('#')) return

const separatorIndex = trimmed.indexOf('=')
if (separatorIndex === -1) return

const key = trimmed.slice(0, separatorIndex).trim()
const value = trimmed.slice(separatorIndex + 1).trim().replace(/^['"]|['"]$/g, '')

if (key && process.env[key] === undefined) {
process.env[key] = value
}
})
})
}

loadLocalEnv()

const API_BASE_URL = process.env.TARO_APP_API_BASE_URL || ''

// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
export default defineConfig(async (merge, { command, mode }) => {
const baseConfig = {
Expand All @@ -21,6 +53,7 @@ export default defineConfig(async (merge, { command, mode }) => {
outputRoot: 'dist',
plugins: [],
defineConstants: {
API_BASE_URL: JSON.stringify(API_BASE_URL)
},
copy: {
patterns: [
Expand Down
46 changes: 43 additions & 3 deletions src/api/auth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
import { get, post, put } from '../utils/request'
import { get, post, put, request } from '../utils/request'

export const authAPI = {
wechatLogin(code) {
return post('/api/v0/auth/wechat-login', { code })
wechatLogin(code, options = {}) {
return post('/api/v0/auth/wechat-login', { code }, {
skipAuthRefresh: true,
retryOnAuthFailure: false,
...options
})
},

refresh(refreshToken, options = {}) {
return post('/api/v0/auth/refresh', {
refresh_token: refreshToken
}, {
skipAuthRefresh: true,
retryOnAuthFailure: false,
...options
})
},

logout(options = {}) {
return request({
url: '/api/v0/auth/logout',
method: 'POST',
skipAuthRefresh: true,
retryOnAuthFailure: false,
handleAuthFailure: false,
...options
})
},

logoutAll(options = {}) {
return request({
url: '/api/v0/auth/logout-all',
method: 'POST',
skipAuthRefresh: true,
retryOnAuthFailure: false,
handleAuthFailure: false,
...options
})
}
}

Expand All @@ -13,5 +49,9 @@ export const userAPI = {

updateProfile(data) {
return put('/api/v0/user/profile', data)
},

getLoginDays() {
return get('/api/v0/user/login-days')
}
}
18 changes: 1 addition & 17 deletions src/api/config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { get, post, put, del } from '../utils/request'
import { get } from '../utils/request'

export const configAPI = {
getConfig(key) {
if (!key) return Promise.reject(new Error('Config key is required'))
return get(`/api/v0/config/${key}`)
},

searchConfig(params) {
return get('/api/v0/config/search', params)
},

createConfig(data) {
return post('/api/v0/config/', data)
},

updateConfig(key, data) {
return put(`/api/v0/config/${key}`, data)
},

deleteConfig(key) {
return del(`/api/v0/config/${key}`)
}
}
27 changes: 0 additions & 27 deletions src/api/contribution.js

This file was deleted.

12 changes: 8 additions & 4 deletions src/api/courseTable.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { get, put, post } from '../utils/request'
import { get, put, del } from '../utils/request'

export const courseTableAPI = {
getCourseTable(params) {
return get('/api/v0/coursetable', params)
},

getBindCount() {
return get('/api/v0/coursetable/bind-count')
},

searchClass(params) {
return get('/api/v0/coursetable/search', params)
},
Expand All @@ -17,8 +21,8 @@ export const courseTableAPI = {
return put('/api/v0/coursetable', data)
},

resetBindCount(userId) {
if (!userId) return Promise.reject(new Error('userId is required'))
return post(`/api/v0/coursetable/reset/${userId}`)
deleteSchedule(semester) {
if (!semester) return Promise.reject(new Error('semester is required'))
return del(`/api/v0/coursetable/schedule?semester=${encodeURIComponent(semester)}`)
}
}
19 changes: 19 additions & 0 deletions src/api/gpa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { get, post, del } from '../utils/request'

export const gpaAPI = {
getBackupList() {
return get('/api/v0/gpa/backup')
},

getBackupDetail(id) {
return get(`/api/v0/gpa/backup/${id}`)
},

createBackup(data) {
return post('/api/v0/gpa/backup', data)
},

deleteBackup(id) {
return del(`/api/v0/gpa/backup/${id}`)
}
}
18 changes: 1 addition & 17 deletions src/api/hero.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { get, post, put, del } from '../utils/request'
import { get } from '../utils/request'

export const heroAPI = {
getHeroes() {
return get('/api/v0/heroes/')
},

searchHeroes(params) {
return get('/api/v0/heroes/search', params)
},

createHero(data) {
return post('/api/v0/heroes/', data)
},

updateHero(id, data) {
return put(`/api/v0/heroes/${id}`, data)
},

deleteHero(id) {
return del(`/api/v0/heroes/${id}`)
}
}
5 changes: 3 additions & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export { configAPI } from './config'
export { ossAPI } from './oss'
export { questionsAPI } from './questions'
export { notificationAPI } from './notification'
export { contributionAPI } from './contribution'
export { materialAPI } from './material'
export { systemAPI, statAPI } from './system'
export { pointsAPI } from './points'
export { dictionaryAPI } from './dictionary'
export { rbacAPI } from './rbac'
export { countdownAPI } from './countdown'
export { studyTaskAPI } from './studyTask'
export { pomodoroAPI } from './pomodoro'
export { gpaAPI } from './gpa'
export { organizationAPI } from './organization'
8 changes: 0 additions & 8 deletions src/api/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ export const materialAPI = {
return post(`/api/v0/materials/${md5}/download`)
},

deleteMaterial(md5) {
return del(`/api/v0/admin/materials/${md5}`)
},

updateMaterialDesc(md5, data) {
return put(`/api/v0/admin/material-desc/${md5}`, data)
},

getCategories(params) {
return get('/api/v0/material-categories', params)
}
Expand Down
57 changes: 1 addition & 56 deletions src/api/notification.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, post, put, del } from '../utils/request'
import { get } from '../utils/request'

export const notificationAPI = {
getNotifications(params) {
Expand All @@ -9,63 +9,8 @@ export const notificationAPI = {
return get(`/api/v0/notifications/${id}`)
},

createNotification(data) {
return post('/api/v0/admin/notifications', data)
},

updateNotification(id, data) {
return put(`/api/v0/admin/notifications/${id}`, data)
},

publishNotification(id) {
return post(`/api/v0/admin/notifications/${id}/publish`)
},

publishAdminNotification(id) {
return post(`/api/v0/admin/notifications/${id}/publish-admin`)
},

deleteNotification(id) {
return del(`/api/v0/admin/notifications/${id}`)
},

approveNotification(id, data) {
return post(`/api/v0/admin/notifications/${id}/approve`, data)
},

getAdminNotifications(params) {
return get('/api/v0/admin/notifications', params)
},

getAdminNotificationDetail(id) {
return get(`/api/v0/admin/notifications/${id}`)
},

getCategories() {
return get('/api/v0/categories')
},

createCategory(data) {
return post('/api/v0/admin/categories', data)
},

updateCategory(id, data) {
return put(`/api/v0/admin/categories/${id}`, data)
},

convertToSchedule(id, data) {
return post(`/api/v0/admin/notifications/${id}/schedule`, data)
},

getNotificationStats() {
return get('/api/v0/admin/notifications/stats')
},

pinNotification(id) {
return post(`/api/v0/admin/notifications/${id}/pin`)
},

unpinNotification(id) {
return post(`/api/v0/admin/notifications/${id}/unpin`)
}
}
11 changes: 11 additions & 0 deletions src/api/organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { get } from '../utils/request'

export const organizationAPI = {
getOrganizations(params) {
return get('/api/v0/organizations/', params)
},

getOrganizationDetail(id) {
return get(`/api/v0/organizations/${id}`)
},
}
4 changes: 0 additions & 4 deletions src/api/points.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ export const pointsAPI = {
getStats(params) {
return get('/api/v0/points/stats', params)
},

grantPoints(data) {
return post('/api/v0/points/grant', data)
}
}
Loading