verce-vue-test 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/{mini2.0-main 2/src/App.vue → mini2.0-main/src/App.vue} +1 -1
  2. package/mini2.0-main/src/api/announcement.ts +405 -0
  3. package/mini2.0-main/src/api/rmb-position.ts +139 -0
  4. package/mini2.0-main/src/api/tam.ts +170 -0
  5. package/{mini2.0-main 2/src/api/user.ts → mini2.0-main/src/api/user.ts} +16 -0
  6. package/mini2.0-main/src/config/plugin.properties.test +6 -0
  7. package/{mini2.0-main 2/src/stores/user.ts → mini2.0-main/src/stores/user.ts} +56 -4
  8. package/{mini2.0-main 2/src/types/api.d.ts → mini2.0-main/src/types/api.d.ts} +1 -1
  9. package/{mini2.0-main 2/src/utils/auth-token.ts → mini2.0-main/src/utils/auth-token.ts} +50 -6
  10. package/mini2.0-main/src/utils/code-highlight.ts +165 -0
  11. package/mini2.0-main/src/utils/copy.ts +36 -0
  12. package/{mini2.0-main 2/src/utils/request.ts → mini2.0-main/src/utils/request.ts} +10 -6
  13. package/{mini2.0-main 2/src/views/article-detail/index.vue → mini2.0-main/src/views/article-detail/index.vue} +105 -7
  14. package/{mini2.0-main 2/src/views/article-edit/index.vue → mini2.0-main/src/views/article-edit/index.vue} +121 -16
  15. package/{mini2.0-main 2/src/views/articles/index.vue → mini2.0-main/src/views/articles/index.vue} +8 -8
  16. package/{mini2.0-main 2/src/views/login/index.vue → mini2.0-main/src/views/login/index.vue} +46 -6
  17. package/package.json +1 -1
  18. package/src/utils/code-highlight.ts +200 -0
  19. package/src/views/NoticeDetailView.vue +69 -1
  20. package/mini2.0-main 2/src/api/rmb-position.ts +0 -287
  21. package/mini2.0-main 2/src/config/plugin.properties.test +0 -6
  22. /package/{mini2.0-main 2 → mini2.0-main}/.editorconfig +0 -0
  23. /package/{mini2.0-main 2 → mini2.0-main}/.env.development +0 -0
  24. /package/{mini2.0-main 2 → mini2.0-main}/.env.production +0 -0
  25. /package/{mini2.0-main 2 → mini2.0-main}/.env.test +0 -0
  26. /package/{mini2.0-main 2 → mini2.0-main}/.gitattributes +0 -0
  27. /package/{mini2.0-main 2 → mini2.0-main}/.oxlintrc.json +0 -0
  28. /package/{mini2.0-main 2 → mini2.0-main}/.prettierrc.json +0 -0
  29. /package/{mini2.0-main 2 → mini2.0-main}/.vscode/extensions.json +0 -0
  30. /package/{mini2.0-main 2 → mini2.0-main}/README.md +0 -0
  31. /package/{mini2.0-main 2 → mini2.0-main}/auto-imports.d.ts +0 -0
  32. /package/{mini2.0-main 2 → mini2.0-main}/components.d.ts +0 -0
  33. /package/{mini2.0-main 2 → mini2.0-main}/design-qa.md +0 -0
  34. /package/{mini2.0-main 2 → mini2.0-main}/docs/MX_API.md +0 -0
  35. /package/{mini2.0-main 2 → mini2.0-main}/docs/REQUEST.md +0 -0
  36. /package/{mini2.0-main 2 → mini2.0-main}/docs/jsapi.js +0 -0
  37. /package/{mini2.0-main 2 → mini2.0-main}/docs/package-json-guide.md +0 -0
  38. /package/{mini2.0-main 2 → mini2.0-main}/env.d.ts +0 -0
  39. /package/{mini2.0-main 2 → mini2.0-main}/eslint.config.ts +0 -0
  40. /package/{mini2.0-main 2 → mini2.0-main}/index.html +0 -0
  41. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/design-comparison.png +0 -0
  42. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-back-top.png +0 -0
  43. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-page.png +0 -0
  44. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-sticky-check.png +0 -0
  45. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-sticky-scrolled.png +0 -0
  46. /package/{mini2.0-main 2 → mini2.0-main}/package-lock.json +0 -0
  47. /package/{mini2.0-main 2 → mini2.0-main}/package.json +0 -0
  48. /package/{mini2.0-main 2 → mini2.0-main}/plugins/bump-version.ts +0 -0
  49. /package/{mini2.0-main 2 → mini2.0-main}/postcss.config.ts +0 -0
  50. /package/{mini2.0-main 2 → mini2.0-main}/public/favicon.ico +0 -0
  51. /package/{mini2.0-main 2 → mini2.0-main}/public/images/12a73787-86a9-4891-a65f-66104746f6a8.png +0 -0
  52. /package/{mini2.0-main 2 → mini2.0-main}/public/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png +0 -0
  53. /package/{mini2.0-main 2 → mini2.0-main}/public/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png +0 -0
  54. /package/{mini2.0-main 2 → mini2.0-main}/public/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png +0 -0
  55. /package/{mini2.0-main 2 → mini2.0-main}/public/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png +0 -0
  56. /package/{mini2.0-main 2 → mini2.0-main}/public/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png +0 -0
  57. /package/{mini2.0-main 2 → mini2.0-main}/public/images/f5876785-b927-4347-ba19-999114240649.png +0 -0
  58. /package/{mini2.0-main 2 → mini2.0-main}/public/images/img.png +0 -0
  59. /package/{mini2.0-main 2 → mini2.0-main}/src/api/health.ts +0 -0
  60. /package/{mini2.0-main 2 → mini2.0-main}/src/auto-imports.d.ts +0 -0
  61. /package/{mini2.0-main 2 → mini2.0-main}/src/components.d.ts +0 -0
  62. /package/{mini2.0-main 2 → mini2.0-main}/src/config/config.properties +0 -0
  63. /package/{mini2.0-main 2 → mini2.0-main}/src/config/env.ts +0 -0
  64. /package/{mini2.0-main 2 → mini2.0-main}/src/config/plugin.properties.pro +0 -0
  65. /package/{mini2.0-main 2 → mini2.0-main}/src/core/mxApi/index.ts +0 -0
  66. /package/{mini2.0-main 2 → mini2.0-main}/src/core/request/index.ts +0 -0
  67. /package/{mini2.0-main 2 → mini2.0-main}/src/main.ts +0 -0
  68. /package/{mini2.0-main 2 → mini2.0-main}/src/router/index.ts +0 -0
  69. /package/{mini2.0-main 2 → mini2.0-main}/src/stores/app.ts +0 -0
  70. /package/{mini2.0-main 2 → mini2.0-main}/src/stores/counter.ts +0 -0
  71. /package/{mini2.0-main 2 → mini2.0-main}/src/types/nprogress.d.ts +0 -0
  72. /package/{mini2.0-main 2 → mini2.0-main}/src/utils/query.ts +0 -0
  73. /package/{mini2.0-main 2 → mini2.0-main}/src/views/clearing-detail/index.vue +0 -0
  74. /package/{mini2.0-main 2 → mini2.0-main}/src/views/foreign-position/index.vue +0 -0
  75. /package/{mini2.0-main 2 → mini2.0-main}/src/views/home/index.vue +0 -0
  76. /package/{mini2.0-main 2 → mini2.0-main}/src/views/mine/index.vue +0 -0
  77. /package/{mini2.0-main 2 → mini2.0-main}/src/views/net-debit/index.vue +0 -0
  78. /package/{mini2.0-main 2 → mini2.0-main}/src/views/pbc-position/index.vue +0 -0
  79. /package/{mini2.0-main 2 → mini2.0-main}/src/views/position-estimate/index.vue +0 -0
  80. /package/{mini2.0-main 2 → mini2.0-main}/src/views/rmb-position/index.vue +0 -0
  81. /package/{mini2.0-main 2 → mini2.0-main}/src/views/warning/index.vue +0 -0
  82. /package/{mini2.0-main 2 → mini2.0-main}/tsconfig.app.json +0 -0
  83. /package/{mini2.0-main 2 → mini2.0-main}/tsconfig.json +0 -0
  84. /package/{mini2.0-main 2 → mini2.0-main}/tsconfig.node.json +0 -0
  85. /package/{mini2.0-main 2 → mini2.0-main}/vite.config.ts +0 -0
@@ -7,10 +7,26 @@ interface UserInfo {
7
7
  avatar: string
8
8
  }
9
9
 
10
+ export type UserOrg = {
11
+ orgNo: string
12
+ orgCnAbre: string
13
+ SORTNO: number
14
+ orgId: string
15
+ }
16
+
10
17
  export function getUserInfoApi(id: number) {
11
18
  return request<UserInfo>({ url: `/user/${id}` })
12
19
  }
13
20
 
21
+ export function getOrgByUserNameApi(username: string) {
22
+ return request<UserOrg[]>({
23
+ url: '/uaa/user/getOrgByUserName',
24
+ params: {
25
+ username,
26
+ },
27
+ })
28
+ }
29
+
14
30
  export function loginApi(data: { username: string; password: string }) {
15
31
  return request<AuthTokenResponse>({
16
32
  url: '/uaa/oauth/token',
@@ -0,0 +1,6 @@
1
+ app_id=vue_demo;
2
+ version_code=10001;
3
+ version_name=1.0.0.01;
4
+ type=html5;
5
+ frame=vue;
6
+ platform=[mac,win,ios,android];
@@ -1,12 +1,17 @@
1
1
  import { defineStore } from 'pinia'
2
+ import type { UserOrg } from '@/api/user'
3
+ import type { AuthTokenPayload } from '@/utils/auth-token'
2
4
 
3
5
  const LEGACY_TOKEN_KEYS = ['token', 'refresh_token', 'user']
4
6
 
7
+ /** 用户登录态在本地存储中的 key,由 pinia-plugin-persistedstate 使用。 */
8
+ const AUTH_PERSIST_KEY = 'mini2_user_auth'
9
+
5
10
  /**
6
11
  * 用户状态 Store
7
12
  *
8
13
  * 使用 Composition API 风格(setup 语法)定义。
9
- * token 只保存在 Pinia 内存态中,刷新页面后需要重新登录或通过敏行自动登录恢复。
14
+ * 登录信息通过 pinia-plugin-persistedstate 保存到本地,刷新页面后可继续使用。
10
15
  */
11
16
  export const useUserStore = defineStore(
12
17
  'user',
@@ -15,12 +20,18 @@ export const useUserStore = defineStore(
15
20
  // -------------------------------- State --------------------------------
16
21
 
17
22
  /** 登录凭证,登录成功后由后端返回,后续请求通过请求头携带 */
18
- const token = ref('1')
23
+ const token = ref('')
19
24
  const refreshToken = ref('')
20
25
  const username = ref('')
21
26
  const realName = ref('')
22
27
  const organizationName = ref('')
23
28
 
29
+ /** 登录接口原始返回信息,已在保存前去除敏感字段。 */
30
+ const authPayload = ref<AuthTokenPayload | null>(null)
31
+
32
+ /** 当前登录机构,登录后取机构列表第一条。 */
33
+ const loginOrg = ref<UserOrg | null>(null)
34
+
24
35
  clearLegacyStoredTokens()
25
36
 
26
37
  // ------------------------------ Actions --------------------------------
@@ -37,20 +48,41 @@ export const useUserStore = defineStore(
37
48
  refreshToken.value = value
38
49
  }
39
50
 
40
- function setAuthTokens(accessToken: string, newRefreshToken?: string) {
51
+ function setAuthTokens(
52
+ accessToken: string,
53
+ newRefreshToken?: string,
54
+ payload?: AuthTokenPayload,
55
+ ) {
41
56
  setToken(accessToken)
42
57
 
43
58
  if (newRefreshToken) {
44
59
  setRefreshToken(newRefreshToken)
45
60
  }
61
+
62
+ if (payload) {
63
+ authPayload.value = payload
64
+ }
46
65
  }
47
66
 
48
- function setUserInfo(info: { username?: string; realName?: string; organizationName?: string }) {
67
+ function setUserInfo(info: {
68
+ username?: string
69
+ realName?: string
70
+ organizationName?: string
71
+ }) {
49
72
  username.value = info.username || username.value
50
73
  realName.value = info.realName || realName.value
51
74
  organizationName.value = info.organizationName || organizationName.value
52
75
  }
53
76
 
77
+ function setAuthPayload(payload: AuthTokenPayload | null) {
78
+ authPayload.value = payload
79
+ }
80
+
81
+ function setLoginOrg(org: UserOrg) {
82
+ loginOrg.value = org
83
+ organizationName.value = org.orgCnAbre || organizationName.value
84
+ }
85
+
54
86
  /**
55
87
  * 清空 token
56
88
  * 退出登录或刷新 token 失败时调用。
@@ -61,6 +93,8 @@ export const useUserStore = defineStore(
61
93
  username.value = ''
62
94
  realName.value = ''
63
95
  organizationName.value = ''
96
+ authPayload.value = null
97
+ loginOrg.value = null
64
98
  }
65
99
 
66
100
  // ----------------------------- Return ----------------------------------
@@ -71,13 +105,31 @@ export const useUserStore = defineStore(
71
105
  username,
72
106
  realName,
73
107
  organizationName,
108
+ authPayload,
109
+ loginOrg,
74
110
  setToken,
75
111
  setRefreshToken,
76
112
  setAuthTokens,
77
113
  setUserInfo,
114
+ setAuthPayload,
115
+ setLoginOrg,
78
116
  clearToken,
79
117
  }
80
118
  },
119
+ {
120
+ persist: {
121
+ key: AUTH_PERSIST_KEY,
122
+ pick: [
123
+ 'token',
124
+ 'refreshToken',
125
+ 'username',
126
+ 'realName',
127
+ 'organizationName',
128
+ 'authPayload',
129
+ 'loginOrg',
130
+ ],
131
+ },
132
+ },
81
133
  )
82
134
 
83
135
  function clearLegacyStoredTokens() {
@@ -1,6 +1,6 @@
1
1
  /** 后端统一响应格式 */
2
2
  export interface ApiResponse<T = unknown> {
3
- code: number
3
+ code: number | string
4
4
  message: string
5
5
  data: T
6
6
  }
@@ -3,7 +3,15 @@ import { useUserStore } from '@/stores/user'
3
3
  export const REFRESH_TOKEN_URL = '/uaa/oauth/mobile/refresh_token'
4
4
 
5
5
  export type AuthPrincipal = {
6
+ branchId?: string
7
+ currentOrgId?: string
8
+ ip?: string
9
+ loginIp?: string
10
+ orgId?: string
11
+ orgIds?: string[]
12
+ reqIpAddr?: string
6
13
  username?: string
14
+ userId?: string
7
15
  userRealName?: string
8
16
  organizationName?: string
9
17
  orgName?: string
@@ -54,11 +62,18 @@ export type AuthTokenResponse = AuthTokenPayload & {
54
62
  let refreshTokenPromise: Promise<string> | null = null
55
63
 
56
64
  export function getAccessTokenFromResponse(response: AuthTokenResponse) {
57
- return response.data?.token || response.data?.access_token || response.token || response.access_token
65
+ return (
66
+ response.data?.token || response.data?.access_token || response.token || response.access_token
67
+ )
58
68
  }
59
69
 
60
70
  export function getRefreshTokenFromResponse(response: AuthTokenResponse) {
61
- return response.data?.refresh_token || response.data?.refreshToken || response.refresh_token || response.refreshToken
71
+ return (
72
+ response.data?.refresh_token ||
73
+ response.data?.refreshToken ||
74
+ response.refresh_token ||
75
+ response.refreshToken
76
+ )
62
77
  }
63
78
 
64
79
  export function getStoredAccessToken() {
@@ -81,16 +96,18 @@ export function getAuthHeaders(headers?: Record<string, string>, skipAuth = fals
81
96
  }
82
97
 
83
98
  export function saveAuthTokens(response: AuthTokenResponse) {
99
+ const payload = getAuthPayloadFromResponse(response)
100
+ const payloadForStorage = sanitizeAuthPayload(payload)
84
101
  const token = getAccessTokenFromResponse(response)
85
102
  const refreshToken = getRefreshTokenFromResponse(response)
86
- const principal = getPrincipalFromResponse(response)
103
+ const principal = payload.principal
87
104
 
88
105
  if (!token) {
89
106
  throw new Error('接口未返回业务 token')
90
107
  }
91
108
 
92
109
  const userStore = useUserStore()
93
- userStore.setAuthTokens(token, refreshToken)
110
+ userStore.setAuthTokens(token, refreshToken, payloadForStorage)
94
111
  userStore.setUserInfo({
95
112
  username: principal?.username,
96
113
  realName: principal?.userRealName,
@@ -100,8 +117,35 @@ export function saveAuthTokens(response: AuthTokenResponse) {
100
117
  return token
101
118
  }
102
119
 
103
- function getPrincipalFromResponse(response: AuthTokenResponse) {
104
- return response.data?.principal || response.principal
120
+ function getAuthPayloadFromResponse(response: AuthTokenResponse) {
121
+ // 登录接口可能直接返回 token,也可能包一层 data;这里统一取真正的认证载荷。
122
+ if (isAuthPayload(response.data)) {
123
+ return response.data
124
+ }
125
+
126
+ return response
127
+ }
128
+
129
+ function isAuthPayload(payload?: AuthTokenPayload): payload is AuthTokenPayload {
130
+ return Boolean(
131
+ payload &&
132
+ (payload.token ||
133
+ payload.access_token ||
134
+ payload.refresh_token ||
135
+ payload.refreshToken ||
136
+ payload.principal),
137
+ )
138
+ }
139
+
140
+ function sanitizeAuthPayload(payload: AuthTokenPayload): AuthTokenPayload {
141
+ if (!payload.principal) return payload
142
+
143
+ // 后端 principal 里会带 password 哈希,本地只保存业务需要的用户信息。
144
+ const { password: _password, ...principal } = payload.principal
145
+ return {
146
+ ...payload,
147
+ principal,
148
+ }
105
149
  }
106
150
 
107
151
  function getOrganizationNameFromPrincipal(principal?: AuthPrincipal) {
@@ -0,0 +1,165 @@
1
+ const KEYWORDS = new Set([
2
+ 'abstract',
3
+ 'async',
4
+ 'await',
5
+ 'boolean',
6
+ 'break',
7
+ 'case',
8
+ 'catch',
9
+ 'class',
10
+ 'const',
11
+ 'continue',
12
+ 'default',
13
+ 'delete',
14
+ 'do',
15
+ 'else',
16
+ 'enum',
17
+ 'export',
18
+ 'extends',
19
+ 'false',
20
+ 'finally',
21
+ 'for',
22
+ 'from',
23
+ 'function',
24
+ 'if',
25
+ 'import',
26
+ 'in',
27
+ 'interface',
28
+ 'let',
29
+ 'new',
30
+ 'null',
31
+ 'number',
32
+ 'private',
33
+ 'protected',
34
+ 'public',
35
+ 'return',
36
+ 'static',
37
+ 'string',
38
+ 'super',
39
+ 'switch',
40
+ 'this',
41
+ 'throw',
42
+ 'true',
43
+ 'try',
44
+ 'type',
45
+ 'typeof',
46
+ 'undefined',
47
+ 'var',
48
+ 'void',
49
+ 'while',
50
+ ])
51
+
52
+ const TOKEN_PATTERN =
53
+ /(\/\*[\s\S]*?\*\/|\/\/[^\n]*|#[^\n]*|<!--[\s\S]*?-->|(["'`])(?:\\[\s\S]|(?!\2)[^\\])*\2|<\/?[A-Za-z][^>\n]*?>|\b\d+(?:\.\d+)?\b|\b[A-Za-z_$][\w$]*\b)/g
54
+
55
+ export function highlightArticleHtml(html: string) {
56
+ if (!html.trim()) {
57
+ return ''
58
+ }
59
+
60
+ const doc = new DOMParser().parseFromString(`<article>${html}</article>`, 'text/html')
61
+ const root = doc.body.firstElementChild
62
+
63
+ if (!root) {
64
+ return html
65
+ }
66
+
67
+ root.querySelectorAll('pre code').forEach((code) => {
68
+ const rawCode = code.textContent || ''
69
+ const language = getLanguage(code)
70
+
71
+ code.innerHTML = highlightCode(rawCode)
72
+ code.classList.add('code-highlighted')
73
+
74
+ if (language) {
75
+ code.setAttribute('data-language', language)
76
+ }
77
+ })
78
+
79
+ return root.innerHTML
80
+ }
81
+
82
+ function highlightCode(code: string) {
83
+ let html = ''
84
+ let lastIndex = 0
85
+
86
+ code.replace(TOKEN_PATTERN, (...args) => {
87
+ const token = args[0]
88
+ const offset = args[args.length - 2] as number
89
+
90
+ html += escapeHtml(code.slice(lastIndex, offset))
91
+ html += renderToken(token)
92
+ lastIndex = offset + token.length
93
+
94
+ return token
95
+ })
96
+
97
+ html += escapeHtml(code.slice(lastIndex))
98
+
99
+ return html
100
+ }
101
+
102
+ function renderToken(token: string) {
103
+ if (isComment(token)) {
104
+ return wrapToken(token, 'hl-comment')
105
+ }
106
+
107
+ if (isString(token)) {
108
+ return wrapToken(token, 'hl-string')
109
+ }
110
+
111
+ if (isTag(token)) {
112
+ return wrapToken(token, 'hl-tag')
113
+ }
114
+
115
+ if (isNumber(token)) {
116
+ return wrapToken(token, 'hl-number')
117
+ }
118
+
119
+ if (KEYWORDS.has(token)) {
120
+ return wrapToken(token, 'hl-keyword')
121
+ }
122
+
123
+ return escapeHtml(token)
124
+ }
125
+
126
+ function wrapToken(token: string, className: string) {
127
+ return `<span class="${className}">${escapeHtml(token)}</span>`
128
+ }
129
+
130
+ function getLanguage(code: Element) {
131
+ const languageAttr = code.getAttribute('data-language')
132
+ const languageClass = Array.from(code.classList).find((className) =>
133
+ className.startsWith('language-'),
134
+ )
135
+
136
+ return languageAttr || languageClass?.replace(/^language-/, '') || ''
137
+ }
138
+
139
+ function isComment(token: string) {
140
+ return (
141
+ token.startsWith('//') ||
142
+ token.startsWith('/*') ||
143
+ token.startsWith('#') ||
144
+ token.startsWith('<!--')
145
+ )
146
+ }
147
+
148
+ function isString(token: string) {
149
+ return /^["'`]/.test(token)
150
+ }
151
+
152
+ function isTag(token: string) {
153
+ return /^<\/?[A-Za-z]/.test(token)
154
+ }
155
+
156
+ function isNumber(token: string) {
157
+ return /^\d/.test(token)
158
+ }
159
+
160
+ function escapeHtml(value: string) {
161
+ const div = document.createElement('div')
162
+ div.textContent = value
163
+
164
+ return div.innerHTML
165
+ }
@@ -0,0 +1,36 @@
1
+ export async function copyText(text: string) {
2
+ if (window.isSecureContext && navigator.clipboard?.writeText) {
3
+ try {
4
+ await navigator.clipboard.writeText(text)
5
+ return
6
+ } catch {
7
+ // HTTP 部署或宿主 WebView 里经常不可用,继续走兼容方案。
8
+ }
9
+ }
10
+
11
+ fallbackCopyText(text)
12
+ }
13
+
14
+ function fallbackCopyText(text: string) {
15
+ const textarea = document.createElement('textarea')
16
+ const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null
17
+
18
+ textarea.value = text
19
+ textarea.setAttribute('readonly', 'true')
20
+ textarea.style.position = 'fixed'
21
+ textarea.style.left = '-9999px'
22
+ textarea.style.top = '0'
23
+ textarea.style.opacity = '0'
24
+ document.body.appendChild(textarea)
25
+ textarea.select()
26
+ textarea.setSelectionRange(0, textarea.value.length)
27
+
28
+ const copied = document.execCommand('copy')
29
+
30
+ document.body.removeChild(textarea)
31
+ previousFocus?.focus()
32
+
33
+ if (!copied) {
34
+ throw new Error('复制失败')
35
+ }
36
+ }
@@ -82,8 +82,8 @@ service.interceptors.response.use(
82
82
  // 普通业务接口返回 { code, message, data };OAuth 登录接口直接返回 token 结构。
83
83
  const res = response.data
84
84
 
85
- // 只有响应体明确包含 code 字段时,才按统一业务格式判断。
86
- if (typeof res.code !== 'undefined' && res.code !== 0) {
85
+ // 只有响应体明确包含 code 字段时,才按统一业务格式判断,兼容 0 和 "0000" 两种成功码。
86
+ if (typeof res.code !== 'undefined' && !isSuccessCode(res.code)) {
87
87
  showToast(res.message || '请求失败')
88
88
 
89
89
  // 将业务错误抛出,调用方可通过 catch 捕获
@@ -130,9 +130,7 @@ service.interceptors.response.use(
130
130
 
131
131
  // 优先取映射表中的提示,没有则显示状态码;无 response 说明是网络异常
132
132
  const status = error.response?.status as number
133
- const message = error.response
134
- ? statusCodeMap[status] || `连接错误 ${status}`
135
- : '网络连接异常'
133
+ const message = error.response ? statusCodeMap[status] || `连接错误 ${status}` : '网络连接异常'
136
134
 
137
135
  showToast(message)
138
136
 
@@ -150,6 +148,10 @@ function shouldRefreshToken(config: AuthAxiosRequestConfig) {
150
148
  return !config.skipAuth && !config._retry && Boolean(getStoredRefreshToken())
151
149
  }
152
150
 
151
+ function isSuccessCode(code: ApiResponse['code']) {
152
+ return code === 0 || code === '0' || code === '0000'
153
+ }
154
+
153
155
  async function requestRefreshTokenByAxios() {
154
156
  const refreshToken = getStoredRefreshToken()
155
157
 
@@ -215,7 +217,9 @@ export interface RequestConfig<T = unknown> {
215
217
  * data: { username: 'admin', password: '123' }
216
218
  * })
217
219
  */
218
- export function request<R = unknown, T = unknown>(config: RequestConfig<T>): Promise<ApiResponse<R>> {
220
+ export function request<R = unknown, T = unknown>(
221
+ config: RequestConfig<T>,
222
+ ): Promise<ApiResponse<R>> {
219
223
  const axiosConfig: AuthAxiosRequestConfig<T> = {
220
224
  url: config.url,
221
225
  method: config.method || 'GET',
@@ -1,4 +1,6 @@
1
1
  <script setup lang="ts">
2
+ import { highlightArticleHtml } from '@/utils/code-highlight'
3
+ import { copyText } from '@/utils/copy'
2
4
  import { formatArticleDate, getArticleDetail, type Article } from '@/api/announcement'
3
5
 
4
6
  defineOptions({ name: 'ArticleDetailPage' })
@@ -10,6 +12,7 @@ const articleId = computed(() => String(route.params.id || ''))
10
12
  const article = ref<Article>()
11
13
  const loading = ref(false)
12
14
  const loadError = ref(false)
15
+ const highlightedContent = computed(() => (article.value ? highlightArticleHtml(article.value.content) : ''))
13
16
 
14
17
  onMounted(() => {
15
18
  loadArticle()
@@ -27,7 +30,7 @@ async function loadArticle() {
27
30
  try {
28
31
  article.value = await getArticleDetail(articleId.value)
29
32
  } catch (error) {
30
- console.error('[文章] 详情加载失败', error)
33
+ console.error('[公告] 详情加载失败', error)
31
34
  loadError.value = true
32
35
  } finally {
33
36
  loading.value = false
@@ -43,6 +46,42 @@ function editArticle() {
43
46
  router.push(`/articles/${article.value.id}/edit`)
44
47
  }
45
48
  }
49
+
50
+ async function copyArticleContent() {
51
+ if (!article.value) {
52
+ return
53
+ }
54
+
55
+ const text = articleContentToText(article.value.content)
56
+
57
+ if (!text) {
58
+ showToast('暂无可复制内容')
59
+ return
60
+ }
61
+
62
+ try {
63
+ await copyText(text)
64
+ showToast('已复制内容')
65
+ } catch (error) {
66
+ console.error('[公告] 内容复制失败', error)
67
+ showToast('复制失败')
68
+ }
69
+ }
70
+
71
+ function articleContentToText(html: string) {
72
+ const doc = new DOMParser().parseFromString(`<article>${html}</article>`, 'text/html')
73
+ const root = doc.body.firstElementChild
74
+
75
+ if (!root) {
76
+ return ''
77
+ }
78
+
79
+ root.querySelectorAll('pre code').forEach((code) => {
80
+ code.replaceWith(doc.createTextNode(`\n${code.textContent || ''}\n`))
81
+ })
82
+
83
+ return root.textContent?.replace(/\n{3,}/g, '\n\n').trim() || ''
84
+ }
46
85
  </script>
47
86
 
48
87
  <template>
@@ -51,8 +90,8 @@ function editArticle() {
51
90
  <button class="header-icon-btn" type="button" aria-label="返回" @click="goBack">
52
91
  <van-icon name="arrow-left" />
53
92
  </button>
54
- <h1>文章详情</h1>
55
- <button class="header-icon-btn accent" type="button" aria-label="编辑文章" @click="editArticle">
93
+ <h1>公告详情</h1>
94
+ <button class="header-icon-btn accent" type="button" aria-label="编辑公告" @click="editArticle">
56
95
  <van-icon name="edit" />
57
96
  </button>
58
97
  </header>
@@ -70,17 +109,20 @@ function editArticle() {
70
109
  </div>
71
110
  </div>
72
111
 
73
- <div class="article-content" v-html="article.content"></div>
112
+ <div class="article-content" v-html="highlightedContent"></div>
74
113
 
75
114
  <footer class="detail-actions">
76
- <van-button block type="danger" @click="editArticle">编辑文章</van-button>
115
+ <van-button block plain type="danger" icon="description-o" @click="copyArticleContent">
116
+ 复制内容
117
+ </van-button>
118
+ <van-button block type="danger" @click="editArticle">编辑公告</van-button>
77
119
  </footer>
78
120
  </article>
79
121
 
80
- <van-empty v-else image="error" :description="loadError ? '文章加载失败' : '文章不存在'">
122
+ <van-empty v-else image="error" :description="loadError ? '公告加载失败' : '公告不存在'">
81
123
  <van-button v-if="loadError" round type="danger" @click="loadArticle">重试</van-button>
82
124
  <van-button v-else round type="danger" @click="router.replace('/articles')">
83
- 返回文章列表
125
+ 返回公告列表
84
126
  </van-button>
85
127
  </van-empty>
86
128
  </main>
@@ -189,6 +231,7 @@ function editArticle() {
189
231
  .article-content :deep(h3),
190
232
  .article-content :deep(p),
191
233
  .article-content :deep(blockquote),
234
+ .article-content :deep(pre),
192
235
  .article-content :deep(ul),
193
236
  .article-content :deep(ol) {
194
237
  margin: 0 0 14px;
@@ -227,7 +270,62 @@ function editArticle() {
227
270
  text-decoration: none;
228
271
  }
229
272
 
273
+ .article-content :deep(pre) {
274
+ position: relative;
275
+ overflow-x: auto;
276
+ padding: 13px 14px;
277
+ border: 1px solid #202c38;
278
+ border-radius: 7px;
279
+ background: #101820;
280
+ }
281
+
282
+ .article-content :deep(pre code) {
283
+ display: block;
284
+ min-width: max-content;
285
+ color: #eef3f7;
286
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
287
+ font-size: 13px;
288
+ line-height: 1.65;
289
+ white-space: pre;
290
+ }
291
+
292
+ .article-content :deep(pre code[data-language]::before) {
293
+ content: attr(data-language);
294
+ position: sticky;
295
+ left: 0;
296
+ display: block;
297
+ width: fit-content;
298
+ margin-bottom: 8px;
299
+ color: #7f8b99;
300
+ font-family: inherit;
301
+ font-size: 11px;
302
+ line-height: 1;
303
+ }
304
+
305
+ .article-content :deep(.hl-keyword) {
306
+ color: #ff8aa0;
307
+ }
308
+
309
+ .article-content :deep(.hl-string) {
310
+ color: #8bdc8b;
311
+ }
312
+
313
+ .article-content :deep(.hl-number) {
314
+ color: #ffd36e;
315
+ }
316
+
317
+ .article-content :deep(.hl-comment) {
318
+ color: #7f8b99;
319
+ }
320
+
321
+ .article-content :deep(.hl-tag) {
322
+ color: #7cc7ff;
323
+ }
324
+
230
325
  .detail-actions {
326
+ display: grid;
327
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
328
+ gap: 10px;
231
329
  margin-top: 28px;
232
330
  }
233
331