artalk 2.7.1 → 2.7.2

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 (173) hide show
  1. package/README.md +1 -1
  2. package/dist/Artalk.css +1 -1
  3. package/dist/Artalk.es.js +155 -147
  4. package/dist/Artalk.es.js.map +1 -1
  5. package/dist/Artalk.iife.js +1 -1
  6. package/dist/Artalk.iife.js.map +1 -1
  7. package/dist/Artalk.js +1 -1
  8. package/dist/Artalk.js.map +1 -1
  9. package/dist/ArtalkLite.css +1 -1
  10. package/dist/ArtalkLite.es.js +155 -147
  11. package/dist/ArtalkLite.es.js.map +1 -1
  12. package/dist/ArtalkLite.iife.js +1 -1
  13. package/dist/ArtalkLite.iife.js.map +1 -1
  14. package/dist/ArtalkLite.js +1 -1
  15. package/dist/ArtalkLite.js.map +1 -1
  16. package/dist/i18n/jp.js +1 -1
  17. package/dist/i18n/zh-TW.js +1 -1
  18. package/dist/src/api/_base.d.ts +7 -0
  19. package/dist/src/api/_options.d.ts +5 -0
  20. package/dist/src/components/checker/index.d.ts +2 -0
  21. package/dist/src/i18n/en.d.ts +1 -0
  22. package/dist/src/i18n/external.d.ts +1 -0
  23. package/dist/src/i18n/index.d.ts +3 -0
  24. package/dist/src/i18n/jp.d.ts +1 -0
  25. package/dist/src/i18n/zh-TW.d.ts +1 -0
  26. package/dist/src/lib/user.d.ts +8 -6
  27. package/dist/src/plugins/editor/_kit.d.ts +7 -1
  28. package/dist/src/service.d.ts +2 -8
  29. package/dist/types/event.d.ts +1 -1
  30. package/package.json +43 -17
  31. package/dist/src/components/dark-mode.d.ts +0 -2
  32. package/src/api/_base.ts +0 -18
  33. package/src/api/_options.ts +0 -25
  34. package/src/api/_request.ts +0 -104
  35. package/src/api/admin.ts +0 -18
  36. package/src/api/captcha.ts +0 -24
  37. package/src/api/comment.ts +0 -84
  38. package/src/api/index.ts +0 -29
  39. package/src/api/page.ts +0 -83
  40. package/src/api/site.ts +0 -51
  41. package/src/api/system.ts +0 -49
  42. package/src/api/upload.ts +0 -28
  43. package/src/api/user.ts +0 -132
  44. package/src/artalk.ts +0 -115
  45. package/src/comment/actions.ts +0 -83
  46. package/src/comment/comment.html +0 -18
  47. package/src/comment/comment.ts +0 -192
  48. package/src/comment/height-limit.ts +0 -100
  49. package/src/comment/index.ts +0 -3
  50. package/src/comment/render.ts +0 -150
  51. package/src/comment/renders/actions.ts +0 -114
  52. package/src/comment/renders/avatar.ts +0 -22
  53. package/src/comment/renders/content.ts +0 -39
  54. package/src/comment/renders/header.ts +0 -84
  55. package/src/comment/renders/index.ts +0 -19
  56. package/src/comment/renders/pending.ts +0 -12
  57. package/src/comment/renders/reply-at.ts +0 -16
  58. package/src/comment/renders/reply-to.ts +0 -24
  59. package/src/components/action-btn.ts +0 -170
  60. package/src/components/checker/admin.ts +0 -37
  61. package/src/components/checker/captcha-renders.ts +0 -69
  62. package/src/components/checker/captcha.ts +0 -26
  63. package/src/components/checker/index.ts +0 -192
  64. package/src/components/dark-mode.ts +0 -30
  65. package/src/components/dialog.ts +0 -62
  66. package/src/components/error-dialog.ts +0 -35
  67. package/src/components/pagination.ts +0 -153
  68. package/src/components/read-more-btn.ts +0 -92
  69. package/src/config.ts +0 -119
  70. package/src/context.ts +0 -146
  71. package/src/data.ts +0 -110
  72. package/src/defaults.ts +0 -61
  73. package/src/editor/editor.html +0 -18
  74. package/src/editor/editor.ts +0 -114
  75. package/src/editor/state.ts +0 -52
  76. package/src/editor/ui.ts +0 -36
  77. package/src/i18n/en.ts +0 -84
  78. package/src/i18n/external.ts +0 -10
  79. package/src/i18n/index.ts +0 -67
  80. package/src/i18n/jp.ts +0 -86
  81. package/src/i18n/zh-CN.ts +0 -88
  82. package/src/i18n/zh-TW.ts +0 -86
  83. package/src/layer/index.ts +0 -4
  84. package/src/layer/layer-manager.ts +0 -32
  85. package/src/layer/layer.ts +0 -39
  86. package/src/layer/scrollbar-helper.ts +0 -24
  87. package/src/layer/sidebar-layer.html +0 -8
  88. package/src/layer/sidebar-layer.ts +0 -155
  89. package/src/layer/wrap.ts +0 -77
  90. package/src/lib/component.ts +0 -12
  91. package/src/lib/detect.ts +0 -222
  92. package/src/lib/event-manager.ts +0 -47
  93. package/src/lib/highlight.ts +0 -5
  94. package/src/lib/marked-renderer.ts +0 -32
  95. package/src/lib/marked.ts +0 -72
  96. package/src/lib/sanitizer.ts +0 -57
  97. package/src/lib/ui.ts +0 -193
  98. package/src/lib/user.ts +0 -55
  99. package/src/lib/utils.ts +0 -236
  100. package/src/list/comment.ts +0 -20
  101. package/src/list/layout.ts +0 -120
  102. package/src/list/list.html +0 -20
  103. package/src/list/list.ts +0 -79
  104. package/src/list/nest.ts +0 -66
  105. package/src/list/page.ts +0 -97
  106. package/src/list/paginator/index.ts +0 -25
  107. package/src/list/paginator/read-more.ts +0 -67
  108. package/src/list/paginator/up-down.ts +0 -51
  109. package/src/main.ts +0 -14
  110. package/src/plugins/admin-only-elem.ts +0 -40
  111. package/src/plugins/conf-remoter.ts +0 -54
  112. package/src/plugins/dark-mode.ts +0 -12
  113. package/src/plugins/editor/_kit.ts +0 -57
  114. package/src/plugins/editor/_plug.ts +0 -60
  115. package/src/plugins/editor/_sample.ts +0 -8
  116. package/src/plugins/editor/closable.ts +0 -44
  117. package/src/plugins/editor/emoticons.scss +0 -72
  118. package/src/plugins/editor/emoticons.ts +0 -293
  119. package/src/plugins/editor/header-event.ts +0 -35
  120. package/src/plugins/editor/header-link.ts +0 -31
  121. package/src/plugins/editor/header-user.ts +0 -98
  122. package/src/plugins/editor/index.ts +0 -40
  123. package/src/plugins/editor/local-storage.ts +0 -36
  124. package/src/plugins/editor/mover.ts +0 -29
  125. package/src/plugins/editor/preview.scss +0 -7
  126. package/src/plugins/editor/preview.ts +0 -41
  127. package/src/plugins/editor/state-edit.ts +0 -116
  128. package/src/plugins/editor/state-reply.ts +0 -91
  129. package/src/plugins/editor/submit-add.ts +0 -33
  130. package/src/plugins/editor/submit-btn.ts +0 -25
  131. package/src/plugins/editor/submit.ts +0 -73
  132. package/src/plugins/editor/textarea.ts +0 -55
  133. package/src/plugins/editor/upload.ts +0 -145
  134. package/src/plugins/editor-kit.ts +0 -161
  135. package/src/plugins/index.ts +0 -16
  136. package/src/plugins/list/copyright.ts +0 -16
  137. package/src/plugins/list/count.ts +0 -31
  138. package/src/plugins/list/dropdown.ts +0 -95
  139. package/src/plugins/list/error-dialog.ts +0 -22
  140. package/src/plugins/list/fetch.ts +0 -64
  141. package/src/plugins/list/goto-first.ts +0 -23
  142. package/src/plugins/list/goto.ts +0 -72
  143. package/src/plugins/list/index.ts +0 -25
  144. package/src/plugins/list/loading.ts +0 -17
  145. package/src/plugins/list/no-comment.ts +0 -25
  146. package/src/plugins/list/reach-bottom.ts +0 -46
  147. package/src/plugins/list/sidebar-btn.ts +0 -39
  148. package/src/plugins/list/time-ticking.ts +0 -22
  149. package/src/plugins/list/unread-badge.ts +0 -26
  150. package/src/plugins/list/unread.ts +0 -38
  151. package/src/plugins/list/with-editor.ts +0 -59
  152. package/src/plugins/markdown.ts +0 -10
  153. package/src/plugins/stat.ts +0 -82
  154. package/src/plugins/version-check.ts +0 -36
  155. package/src/service.ts +0 -91
  156. package/src/style/_color.scss +0 -41
  157. package/src/style/_extend.scss +0 -20
  158. package/src/style/_variables.scss +0 -3
  159. package/src/style/comment.scss +0 -360
  160. package/src/style/editor.scss +0 -194
  161. package/src/style/list.scss +0 -212
  162. package/src/style/main.scss +0 -486
  163. package/src/style/pagination.scss +0 -58
  164. package/src/style/sidebar-layer.scss +0 -92
  165. package/types/config.ts +0 -153
  166. package/types/context.ts +0 -84
  167. package/types/data.ts +0 -271
  168. package/types/editor.ts +0 -95
  169. package/types/event.ts +0 -40
  170. package/types/global.d.ts +0 -1
  171. package/types/index.ts +0 -7
  172. package/types/plugin.ts +0 -3
  173. package/types/sidebar.ts +0 -3
package/src/api/page.ts DELETED
@@ -1,83 +0,0 @@
1
- import type { PageData, CommentData } from '~/types'
2
- import ApiBase from './_base'
3
-
4
- /**
5
- * 页面 API
6
- */
7
- export default class PageApi extends ApiBase {
8
- /** 页面 · 获取 */
9
- public async pageGet(siteName?: string, offset?: number, limit?: number) {
10
- const params: any = {
11
- site_name: siteName || '',
12
- offset: offset || 0,
13
- limit: limit || 15,
14
- }
15
-
16
- const d = await this.POST<any>('/admin/page-get', params)
17
- return (d as { pages: PageData[], total: number })
18
- }
19
-
20
- /** 页面 · 修改 */
21
- public async pageEdit(data: PageData) {
22
- const params: any = {
23
- id: data.id,
24
- key: data.key,
25
- title: data.title,
26
- admin_only: data.admin_only,
27
- site_name: data.site_name || this.options.siteName,
28
- }
29
-
30
- const d = await this.POST<any>('/admin/page-edit', params)
31
- return (d.page as PageData)
32
- }
33
-
34
- /** 页面 · 删除 */
35
- public pageDel(pageKey: string, siteName?: string) {
36
- const params: any = {
37
- key: String(pageKey),
38
- site_name: siteName || '',
39
- }
40
-
41
- return this.POST('/admin/page-del', params)
42
- }
43
-
44
- /** 页面 · 数据更新 */
45
- public async pageFetch(id?: number, siteName?: string, getStatus?: boolean) {
46
- const params: any = {}
47
- if (id) params.id = id
48
- if (siteName) params.site_name = siteName
49
- if (getStatus) params.get_status = getStatus
50
-
51
- const d = await this.POST<any>('/admin/page-fetch', params)
52
- return (d as any)
53
- }
54
-
55
- /** PV */
56
- public async pv() {
57
- const params: any = {
58
- page_key: this.options.pageKey || '',
59
- page_title: this.options.pageTitle || ''
60
- }
61
-
62
- const p = await this.POST<any>('/pv', params)
63
- return p.pv as number
64
- }
65
-
66
- /** 统计 */
67
- public async stat(
68
- type: 'latest_comments'|'latest_pages'|'pv_most_pages'|'comment_most_pages'|
69
- 'page_pv'|'site_pv'|'page_comment'|'site_comment',
70
- pageKeys?: string|string[],
71
- limit?: number
72
- ) {
73
- const params: any = {
74
- type,
75
- }
76
-
77
- if (pageKeys) params.page_keys = Array.isArray(pageKeys) ? pageKeys.join(',') : pageKeys
78
- if (limit) params.limit = limit
79
-
80
- const data = await this.POST<PageData[]|CommentData[]|object|number>(`/stat`, params)
81
- return data
82
- }
83
- }
package/src/api/site.ts DELETED
@@ -1,51 +0,0 @@
1
- import type { SiteData } from '~/types'
2
- import ApiBase from './_base'
3
-
4
- /**
5
- * 站点 API
6
- */
7
- export default class SiteApi extends ApiBase {
8
- /** 站点 · 获取 */
9
- public async siteGet() {
10
- const params: any = {}
11
-
12
- const d = await this.POST<any>('/admin/site-get', params)
13
- return (d.sites as SiteData[])
14
- }
15
-
16
- /** 站点 · 创建 */
17
- public async siteAdd(name: string, urls: string) {
18
- const params: any = {
19
- name, urls,
20
- site_name: '' // 全局保留字段,当前站点名
21
- }
22
-
23
- const d = await this.POST<any>('/admin/site-add', params)
24
- return (d.site as SiteData)
25
- }
26
-
27
- /** 站点 · 修改 */
28
- public async siteEdit(data: SiteData) {
29
- const params: any = {
30
- id: data.id,
31
- name: data.name || '',
32
- urls: data.urls || '',
33
- }
34
-
35
- const d = await this.POST<any>('/admin/site-edit', params)
36
- return (d.site as SiteData)
37
- }
38
-
39
- /** 站点 · 删除 */
40
- public siteDel(id: number, delContent = false) {
41
- const params: any = { id, del_content: delContent }
42
-
43
- return this.POST('/admin/site-del', params)
44
- }
45
-
46
- /** 导出 */
47
- public async export() {
48
- const d = await this.Fetch(`/admin/export`, { method: 'POST' }, 0)
49
- return (d.data?.data || '' as string)
50
- }
51
- }
package/src/api/system.ts DELETED
@@ -1,49 +0,0 @@
1
- import type { ArtalkConfig } from '~/types'
2
- import ApiBase from './_base'
3
-
4
- interface ApiVersionInfo {
5
- app: string
6
- version: string
7
- commit_hash: string
8
- }
9
-
10
- interface SystemConfResp {
11
- frontend_conf: Partial<ArtalkConfig>
12
- version: ApiVersionInfo
13
- }
14
-
15
- /**
16
- * 系统 API
17
- */
18
- export default class SystemApi extends ApiBase {
19
- /** 获取配置 */
20
- public async conf(): Promise<SystemConfResp> {
21
- const data = await this.POST<any>(`/conf`)
22
-
23
- return {
24
- frontend_conf: data.frontend_conf,
25
- version: data.version,
26
- }
27
- }
28
-
29
- /** 获取配置数据 */
30
- public async getSettings() {
31
- const data = await this.POST<{custom: string, template: string}>('/admin/setting-get')
32
- return data
33
- }
34
-
35
- /** 保存配置数据 */
36
- public async saveSettings(yamlStr: string) {
37
- const data = await this.POST<boolean>('/admin/setting-save', {
38
- data: yamlStr,
39
- })
40
- return data
41
- }
42
-
43
- /** 获取 API 版本信息 */
44
- public async version() {
45
- const resp = await fetch(`${this.options.baseURL}/version`, { method: 'POST' })
46
- const data = await resp.json()
47
- return data as { app: string, version: string, commit_hash: string, fe_min_version: string }
48
- }
49
- }
package/src/api/upload.ts DELETED
@@ -1,28 +0,0 @@
1
- import { ToFormData } from './_request'
2
- import ApiBase from './_base'
3
- import User from '../lib/user'
4
-
5
- /**
6
- * 上传 API
7
- */
8
- export default class UploadApi extends ApiBase {
9
- /** 图片上传 */
10
- public async imgUpload(file: File) {
11
- const params: any = {
12
- name: User.data.nick,
13
- email: User.data.email,
14
- page_key: this.options.pageKey,
15
- }
16
-
17
- const form = ToFormData(params)
18
- form.set('file', file)
19
-
20
- const init: RequestInit = {
21
- method: 'POST',
22
- body: form
23
- }
24
-
25
- const json = await this.Fetch('/img-upload', init)
26
- return ((json.data || {}) as any) as { img_file: string, img_url: string }
27
- }
28
- }
package/src/api/user.ts DELETED
@@ -1,132 +0,0 @@
1
- import type { UserData, NotifyData, UserDataForAdmin } from '~/types'
2
- import ApiBase from './_base'
3
- import { ToFormData } from './_request'
4
- import User from '../lib/user'
5
-
6
- /**
7
- * 用户 API
8
- */
9
- export default class UserApi extends ApiBase {
10
- /** 用户 · 登录 */
11
- public async login(name: string, email: string, password: string) {
12
- const params: any = {
13
- name, email, password
14
- }
15
-
16
- const data = await this.POST<any>('/login', params)
17
- return data as { token: string, user: UserData }
18
- }
19
-
20
- /** 用户 · 获取 */
21
- public userGet(name: string, email: string) {
22
- const ctrl = new AbortController()
23
- const params: any = {
24
- name, email
25
- }
26
-
27
- const req = this.Fetch(`/user-get`, {
28
- method: 'POST',
29
- body: ToFormData(params),
30
- signal: ctrl.signal,
31
- }).then((json) => ({
32
- user: json.data.user as UserData|null,
33
- is_login: json.data.is_login as boolean,
34
- unread: (json.data.unread || []) as NotifyData[],
35
- unread_count: json.data.unread_count || 0,
36
- }))
37
-
38
- return {
39
- req,
40
- abort: () => { ctrl.abort() },
41
- }
42
- }
43
-
44
- /** 用户 · 登录状态 */
45
- public async loginStatus() {
46
- const data = await this.POST<any>('/login-status', {
47
- name: User.data.nick,
48
- email: User.data.email
49
- })
50
- return (data || { is_login: false, is_admin: false }) as { is_login: boolean, is_admin: boolean }
51
- }
52
-
53
- /** 用户 · 注销 */
54
- public async logout() {
55
- return this.POST('/logout')
56
- }
57
-
58
- /** 已读标记 */
59
- public markRead(commentID: number, notifyKey: string, readAll = false) {
60
- const params: any = {
61
- comment_id: commentID,
62
- notify_key: notifyKey,
63
- }
64
-
65
- if (readAll) {
66
- delete params.comment_id
67
- delete params.notify_key
68
- params.read_all = true
69
- params.name = User.data.nick
70
- params.email = User.data.email
71
- }
72
-
73
- return this.POST(`/mark-read`, params)
74
- }
75
-
76
- /** 用户 · 列表 */
77
- public async userList(offset?: number, limit?: number, type?: 'all'|'admin'|'in_conf') {
78
- const params: any = {
79
- offset: offset || 0,
80
- limit: limit || 15,
81
- }
82
-
83
- if (type) params.type = type
84
-
85
- const d = await this.POST<any>('/admin/user-get', params)
86
- return (d as { users: UserDataForAdmin[], total: number })
87
- }
88
-
89
- /** 用户 · 新增 */
90
- public async userAdd(user: Partial<UserDataForAdmin>, password?: string) {
91
- const params: any = {
92
- name: user.name || '',
93
- email: user.email || '',
94
- password: password || '',
95
- link: user.link || '',
96
- is_admin: user.is_admin || false,
97
- site_names: user.site_names_raw || '',
98
- receive_email: user.receive_email || true,
99
- badge_name: user.badge_name || '',
100
- badge_color: user.badge_color || '',
101
- }
102
-
103
- const d = await this.POST<any>('/admin/user-add', params)
104
- return (d.user as UserDataForAdmin)
105
- }
106
-
107
- /** 用户 · 修改 */
108
- public async userEdit(user: Partial<UserDataForAdmin>, password?: string) {
109
- const params: any = {
110
- id: user.id,
111
- name: user.name || '',
112
- email: user.email || '',
113
- password: password || '',
114
- link: user.link || '',
115
- is_admin: user.is_admin || false,
116
- site_names: user.site_names_raw || '',
117
- receive_email: user.receive_email || true,
118
- badge_name: user.badge_name || '',
119
- badge_color: user.badge_color || '',
120
- }
121
-
122
- const d = await this.POST<any>('/admin/user-edit', params)
123
- return (d.user as UserDataForAdmin)
124
- }
125
-
126
- /** 用户 · 删除 */
127
- public userDel(userID: number) {
128
- return this.POST('/admin/user-del', {
129
- id: String(userID)
130
- })
131
- }
132
- }
package/src/artalk.ts DELETED
@@ -1,115 +0,0 @@
1
- import './style/main.scss'
2
-
3
- import type { ArtalkConfig, EventPayloadMap, ArtalkPlugin, ContextApi } from '~/types'
4
- import type { EventHandler } from './lib/event-manager'
5
- import ConcreteContext from './context'
6
- import { handelCustomConf, convertApiOptions } from './config'
7
- import Services from './service'
8
- import { DefaultPlugins } from './plugins'
9
- import * as Stat from './plugins/stat'
10
- import Api from './api'
11
-
12
- /** Global Plugins for all instances */
13
- const GlobalPlugins: ArtalkPlugin[] = [ ...DefaultPlugins ]
14
-
15
- /**
16
- * Artalk
17
- *
18
- * @see https://artalk.js.org
19
- */
20
- export default class Artalk {
21
- public conf!: ArtalkConfig
22
- public ctx!: ContextApi
23
- public $root!: HTMLElement
24
-
25
- /** Plugins */
26
- protected plugins: ArtalkPlugin[] = [ ...GlobalPlugins ]
27
-
28
- constructor(conf: Partial<ArtalkConfig>) {
29
- // Init Config
30
- this.conf = handelCustomConf(conf)
31
- if (this.conf.el instanceof HTMLElement) this.$root = this.conf.el
32
-
33
- // Init Context
34
- this.ctx = new ConcreteContext(this.conf, this.$root)
35
-
36
- // Init Services
37
- Object.entries(Services).forEach(([name, initService]) => {
38
- const obj = initService(this.ctx)
39
- if (obj) this.ctx.inject(name as any, obj) // auto inject deps to ctx
40
- })
41
-
42
- // Init Plugins
43
- this.plugins.forEach(plugin => {
44
- if (typeof plugin === 'function') plugin(this.ctx)
45
- })
46
-
47
- // Trigger inited event
48
- this.ctx.trigger('inited')
49
- }
50
-
51
- /** Update config of Artalk */
52
- public update(conf: Partial<ArtalkConfig>) {
53
- this.ctx.updateConf(conf)
54
- return this
55
- }
56
-
57
- /** Reload comment list of Artalk */
58
- public reload() {
59
- this.ctx.reload()
60
- }
61
-
62
- /** Destroy instance of Artalk */
63
- public destroy() {
64
- this.ctx.trigger('destroy')
65
- this.$root.remove()
66
- }
67
-
68
- /** Add an event listener */
69
- public on<K extends keyof EventPayloadMap>(name: K, handler: EventHandler<EventPayloadMap[K]>) {
70
- this.ctx.on(name, handler)
71
- }
72
-
73
- /** Remove an event listener */
74
- public off<K extends keyof EventPayloadMap>(name: K, handler: EventHandler<EventPayloadMap[K]>) {
75
- this.ctx.off(name, handler)
76
- }
77
-
78
- /** Trigger an event */
79
- public trigger<K extends keyof EventPayloadMap>(name: K, payload?: EventPayloadMap[K]) {
80
- this.ctx.trigger(name, payload)
81
- }
82
-
83
- /** Set dark mode */
84
- public setDarkMode(darkMode: boolean) {
85
- this.ctx.setDarkMode(darkMode)
86
- }
87
-
88
- // ===========================
89
- // Static Members
90
- // ===========================
91
-
92
- /** Init Artalk */
93
- public static init(conf: Partial<ArtalkConfig>): Artalk {
94
- return new Artalk(conf)
95
- }
96
-
97
- /** Use plugin, the plugin will be used when Artalk.init */
98
- public static use(plugin: ArtalkPlugin) {
99
- if (GlobalPlugins.includes(plugin)) return
100
- GlobalPlugins.push(plugin)
101
- }
102
-
103
- /** Load count widget */
104
- public static loadCountWidget(c: Partial<ArtalkConfig>) {
105
- const conf = handelCustomConf(c)
106
-
107
- Stat.initCountWidget({
108
- getApi: () => new Api(convertApiOptions(conf)),
109
- pageKey: conf.pageKey,
110
- countEl: conf.countEl,
111
- pvEl: conf.pvEl,
112
- pvAdd: false
113
- })
114
- }
115
- }
@@ -1,83 +0,0 @@
1
- import type Comment from './comment'
2
- import ActionBtn from '../components/action-btn'
3
-
4
- export default class CommentActions {
5
- private comment: Comment
6
-
7
- private get ctx() { return this.comment.ctx }
8
- private get data() { return this.comment.getData() }
9
- private get cConf() { return this.comment.getConf() }
10
-
11
- public constructor(comment: Comment) {
12
- this.comment = comment
13
- }
14
-
15
- /** 投票操作 */
16
- public vote(type: 'up'|'down') {
17
- const actionBtn = (type === 'up') ? this.comment.getRender().voteBtnUp : this.comment.getRender().voteBtnDown
18
-
19
- this.ctx.getApi().comment.vote(this.data.id, `comment_${type}`)
20
- .then((v) => {
21
- this.data.vote_up = v.up
22
- this.data.vote_down = v.down
23
- this.comment.getRender().voteBtnUp?.updateText()
24
- this.comment.getRender().voteBtnDown?.updateText()
25
- })
26
- .catch((err) => {
27
- actionBtn?.setError(this.ctx.$t('voteFail'))
28
- console.log(err)
29
- })
30
- }
31
-
32
- /** 管理员 - 评论状态修改 */
33
- public adminEdit(type: 'collapsed'|'pending'|'pinned', btnElem: ActionBtn) {
34
- if (btnElem.isLoading) return // 若正在修改中
35
-
36
- btnElem.setLoading(true, `${this.ctx.$t('editing')}...`)
37
-
38
- // 克隆并修改当前数据
39
- const modify = { ...this.data }
40
- if (type === 'collapsed') {
41
- modify.is_collapsed = !modify.is_collapsed
42
- } else if (type === 'pending') {
43
- modify.is_pending = !modify.is_pending
44
- } else if (type === 'pinned') {
45
- modify.is_pinned = !modify.is_pinned
46
- }
47
-
48
- this.ctx.getApi().comment.commentEdit(modify).then((data) => {
49
- btnElem.setLoading(false)
50
-
51
- // 刷新当前 Comment UI
52
- this.comment.setData(data)
53
- }).catch((err) => {
54
- console.error(err)
55
- btnElem.setError(this.ctx.$t('editFail'))
56
- })
57
- }
58
-
59
- /** 管理员 - 评论删除 */
60
- public adminDelete(btnElem: ActionBtn) {
61
- if (btnElem.isLoading) return // 若正在删除中
62
-
63
- btnElem.setLoading(true, `${this.ctx.$t('deleting')}...`)
64
- this.ctx.getApi().comment.commentDel(this.data.id, this.data.site_name)
65
- .then(() => {
66
- btnElem.setLoading(false)
67
- if (this.cConf.onDelete) this.cConf.onDelete(this.comment)
68
- })
69
- .catch((e) => {
70
- console.error(e)
71
- btnElem.setError(this.ctx.$t('deleteFail'))
72
- })
73
- }
74
-
75
- /** 快速跳转到该评论 */
76
- public goToReplyComment() {
77
- const origHash = window.location.hash
78
- const modifyHash = `#atk-comment-${this.data.rid}`
79
-
80
- window.location.hash = modifyHash
81
- if (modifyHash === origHash) window.dispatchEvent(new Event('hashchange')) // 强制触发事件
82
- }
83
- }
@@ -1,18 +0,0 @@
1
- <div class="atk-comment-wrap">
2
- <div class="atk-comment">
3
- <div class="atk-avatar"></div>
4
- <div class="atk-main">
5
- <div class="atk-header">
6
- <span class="atk-item atk-nick"></span>
7
- <span class="atk-badge-wrap"></span>
8
- <span class="atk-item atk-date"></span>
9
- </div>
10
- <div class="atk-body">
11
- <div class="atk-content"></div>
12
- </div>
13
- <div class="atk-footer">
14
- <div class="atk-actions"></div>
15
- </div>
16
- </div>
17
- </div>
18
- </div>