artalk 2.4.2 → 2.4.4

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.
@@ -15,17 +15,56 @@ export default class ListLite extends Component {
15
15
  protected data?: ListData
16
16
  protected isLoading: boolean = false
17
17
 
18
- public noCommentText: string // 无评论时显示
18
+ public noCommentText?: string // 无评论时显示
19
+
20
+ /** 嵌套模式下的排序方式 */
21
+ private _nestSortBy?: ListNest.SortByType
22
+ public get nestSortBy() {
23
+ if (this._nestSortBy !== undefined) return this._nestSortBy
24
+ return this.ctx.conf.nestSort || 'DATE_ASC'
25
+ }
26
+ public set nestSortBy(val: ListNest.SortByType) {
27
+ this._nestSortBy = val
28
+ }
19
29
 
20
30
  /** 平铺模式 */
21
- public flatMode = false
31
+ private _flatMode?:boolean
32
+ public get flatMode() {
33
+ if (this._flatMode !== undefined)
34
+ return this._flatMode
35
+
36
+ // 配置开启平铺模式
37
+ if (this.ctx.conf.flatMode === true || Number(this.ctx.conf.nestMax) <= 1)
38
+ return true
22
39
 
23
- /** 嵌套模式 */
24
- public nestSortBy!: ListNest.SortByType
40
+ // 自动判断启用平铺模式
41
+ if (this.ctx.conf.flatMode === 'auto' && window.matchMedia("(max-width: 768px)").matches)
42
+ return true
43
+
44
+ return false
45
+ }
46
+ public set flatMode(val: boolean) {
47
+ this._flatMode = val
48
+ }
49
+
50
+ /** 分页方式 */
51
+ public _pageMode?: 'pagination'|'read-more'
52
+ public get pageMode() {
53
+ return this._pageMode || (this.conf.pagination.readMore ? 'read-more' : 'pagination')
54
+ }
55
+ public set pageMode(val: 'pagination'|'read-more') {
56
+ this._pageMode = val
57
+ }
58
+
59
+ /** 每页数量 (每次请求获取量) */
60
+ private _pageSize?: number
61
+ public get pageSize() {
62
+ return this._pageSize || this.conf.pagination.pageSize
63
+ }
64
+ public set pageSize(val: number) {
65
+ this._pageSize = val
66
+ }
25
67
 
26
- /** 分页 */
27
- public pageMode: 'pagination'|'read-more' = 'pagination'
28
- public pageSize: number = 20 // 每次请求获取量
29
68
  public scrollListenerAt?: HTMLElement // 监听指定元素上的滚动
30
69
  public repositionAt?: HTMLElement // 翻页归位到指定元素
31
70
 
@@ -51,12 +90,6 @@ export default class ListLite extends Component {
51
90
  </div>`)
52
91
  this.$commentsWrap = this.$el.querySelector('.atk-list-comments-wrap')!
53
92
 
54
- // 评论为空时显示字符
55
- this.noCommentText = ctx.conf.noComment || ctx.$t('noComment')
56
-
57
- // 嵌套排序方式
58
- this.nestSortBy = this.ctx.conf.nestSort || 'DATE_ASC'
59
-
60
93
  // 评论时间自动更新
61
94
  window.setInterval(() => {
62
95
  this.$el.querySelectorAll<HTMLElement>('[data-atk-comment-date]').forEach(el => {
@@ -64,6 +97,10 @@ export default class ListLite extends Component {
64
97
  el.innerText = Utils.timeAgo(new Date(Number(date)), this.ctx)
65
98
  })
66
99
  }, 30 * 1000) // 30s 更新一次
100
+
101
+ // 事件监听
102
+ this.ctx.on('conf-loaded', () => {
103
+ })
67
104
  }
68
105
 
69
106
  public getData() {
@@ -99,8 +136,8 @@ export default class ListLite extends Component {
99
136
  // 事件通知(开始加载评论)
100
137
  this.ctx.trigger('list-load')
101
138
 
102
- // 清空评论(加载按钮)
103
- if (isFirstLoad && this.pageMode === 'read-more') {
139
+ // 清空评论(按钮加载更多的第一页、每次加载分页页面)
140
+ if ((this.pageMode === 'read-more' && isFirstLoad) || this.pageMode === 'pagination') {
104
141
  this.ctx.clearAllComments()
105
142
  }
106
143
 
@@ -130,22 +167,25 @@ export default class ListLite extends Component {
130
167
  }
131
168
  }
132
169
 
133
- protected onLoad(data: ListData, offset: number) {
134
- // 清空评论(分页条)
135
- if (this.pageMode === 'pagination') { this.ctx.clearAllComments() }
170
+ private confLoaded = false
136
171
 
172
+ protected onLoad(data: ListData, offset: number) {
137
173
  this.data = data
138
174
 
175
+ // 装载后端提供的配置
176
+ if (!this.confLoaded) {
177
+ if (this.conf.useBackendConf)
178
+ this.ctx.updateConf(data.conf.frontend_conf)
179
+ else
180
+ this.ctx.updateConf({})
181
+ this.confLoaded = true
182
+ }
183
+
139
184
  // 版本检测
140
185
  const feMinVersion = data.api_version?.fe_min_version || '0.0.0'
141
186
  if (this.ctx.conf.versionCheck && this.versionCheck('frontend', feMinVersion, ARTALK_VERSION)) return
142
187
  if (this.ctx.conf.versionCheck && this.versionCheck('backend', backendMinVersion, data.api_version?.version)) return
143
188
 
144
- // 图片上传功能
145
- if (data.conf && typeof data.conf.img_upload === "boolean") {
146
- this.ctx.conf.imgUpload = data.conf.img_upload
147
- }
148
-
149
189
  // 导入数据
150
190
  this.importComments(data.comments)
151
191
 
@@ -157,7 +197,6 @@ export default class ListLite extends Component {
157
197
 
158
198
  this.ctx.updateNotifies(data.unread || [])
159
199
  this.ctx.trigger('list-loaded')
160
- this.ctx.trigger('conf-updated')
161
200
 
162
201
  if (this.onAfterLoad) this.onAfterLoad(data)
163
202
  }
@@ -238,6 +277,10 @@ export default class ListLite extends Component {
238
277
 
239
278
  /** 错误处理 */
240
279
  protected onError(msg: any, offset: number, errData?: any) {
280
+ if (!this.confLoaded) {
281
+ this.ctx.updateConf({})
282
+ }
283
+
241
284
  msg = String(msg)
242
285
  console.error(msg)
243
286
 
@@ -286,7 +329,7 @@ export default class ListLite extends Component {
286
329
  if (isNoComment) {
287
330
  if (!$noComment) {
288
331
  $noComment = Utils.createElement('<div class="atk-list-no-comment"></div>')
289
- $noComment.innerHTML = this.noCommentText
332
+ $noComment.innerHTML = this.noCommentText || this.ctx.conf.noComment || this.ctx.$t('noComment')
290
333
  this.$commentsWrap.appendChild($noComment)
291
334
  }
292
335
  } else {
@@ -473,7 +516,6 @@ export default class ListLite extends Component {
473
516
  ignoreBtn.onclick = () => {
474
517
  Ui.setError(this.$el.parentElement!, null)
475
518
  this.ctx.conf.versionCheck = false
476
- this.ctx.trigger('conf-updated')
477
519
  this.fetchComments(0)
478
520
  }
479
521
  errEl.append(ignoreBtn)
package/src/list/list.ts CHANGED
@@ -23,20 +23,7 @@ export default class List extends ListLite {
23
23
  el.querySelector('.atk-list-body')!.append(this.$el)
24
24
  this.$el = el
25
25
 
26
- // 平铺模式
27
- if (this.ctx.conf.flatMode === true) {
28
- this.flatMode = true // 遵循配置总是开启平铺模式
29
- } else if (this.conf.nestMax && this.conf.nestMax <= 1) {
30
- this.flatMode = true // 嵌套层数值无效时,强制开启平铺模式
31
- } else if (this.ctx.conf.flatMode === 'auto') {
32
- // 自动判断启用平铺模式
33
- if (window.matchMedia("(max-width: 768px)").matches)
34
- this.flatMode = true
35
- }
36
-
37
26
  // 分页模式
38
- this.pageMode = this.conf.pagination.readMore ? 'read-more' : 'pagination'
39
- this.pageSize = this.conf.pagination.pageSize || 20
40
27
  this.repositionAt = this.$el
41
28
 
42
29
  // 操作按钮
@@ -48,11 +35,6 @@ export default class List extends ListLite {
48
35
  })
49
36
  this.$commentCountNum = this.$commentCount.querySelector('.atk-comment-count-num')!
50
37
 
51
- // 评论列表排序 Dropdown 下拉选择层
52
- if (this.ctx.conf.listSort) {
53
- this.initDropdown()
54
- }
55
-
56
38
  // copyright
57
39
  this.$el.querySelector<HTMLElement>('.atk-copyright')!.innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${ARTALK_VERSION}">Artalk</a>`
58
40
 
@@ -104,6 +86,11 @@ export default class List extends ListLite {
104
86
  this.ctx.editorOpen()
105
87
  this.$closeCommentBtn.innerHTML = this.$t('closeComment')
106
88
  }
89
+
90
+ // 评论列表排序 Dropdown 下拉选择层
91
+ if (this.ctx.conf.listSort) {
92
+ this.initDropdown()
93
+ }
107
94
  }
108
95
 
109
96
  protected onLoad(data: ListData, offset: number) {
@@ -197,8 +184,13 @@ export default class List extends ListLite {
197
184
  }
198
185
  }
199
186
 
187
+ private dropdownLoaded = false
188
+
200
189
  /** 初始化选择下拉层 */
201
190
  protected initDropdown() {
191
+ if (this.dropdownLoaded) return
192
+ this.dropdownLoaded = true
193
+
202
194
  this.$dropdownWrap = this.$commentCount
203
195
  this.$commentCount.classList.add('atk-dropdown-wrap')
204
196
 
@@ -1,4 +1,5 @@
1
1
  import { I18n } from '~/src/i18n'
2
+ import { CommentData } from './artalk-data'
2
3
 
3
4
  export default interface ArtalkConfig {
4
5
  /** 装载元素 */
@@ -39,6 +40,9 @@ export default interface ArtalkConfig {
39
40
  default: string
40
41
  }
41
42
 
43
+ /** 头像链接生成器 */
44
+ avatarURLBuilder?: (comment: CommentData) => string,
45
+
42
46
  /** 分页配置 */
43
47
  pagination: {
44
48
  /** 每次请求获取数量 */
@@ -103,7 +107,7 @@ export default interface ArtalkConfig {
103
107
  /** 版本检测 */
104
108
  versionCheck: boolean
105
109
 
106
- /** 应用后端配置 */
110
+ /** 引用后端配置 */
107
111
  useBackendConf: boolean
108
112
 
109
113
  /** 语言本地化 */
@@ -159,6 +159,29 @@ export interface UserData {
159
159
 
160
160
  /** 是否属于管理员 */
161
161
  is_admin: boolean
162
+
163
+ /** 所属站点名 */
164
+ site_names: string[]
165
+
166
+ /** 所属站点名 (字符串) */
167
+ site_names_raw: string,
168
+
169
+ /** 是否允许接收邮件通知 */
170
+ receive_email: boolean
171
+ }
172
+
173
+ export interface UserDataForAdmin extends UserData {
174
+ /** 最后一次操作 IP */
175
+ last_ip: string
176
+
177
+ /** 最后一次操作 UA */
178
+ last_ua: string
179
+
180
+ /** 是否存在于配置文件中 */
181
+ is_in_conf: boolean
182
+
183
+ /** 评论数 */
184
+ comment_count: number
162
185
  }
163
186
 
164
187
  export interface NotifyData {
@@ -143,4 +143,7 @@ export default interface ContextApi {
143
143
 
144
144
  /** 设置暗黑模式 */
145
145
  setDarkMode(darkMode: boolean): void
146
+
147
+ /** 更新配置 */
148
+ updateConf(conf: Partial<ArtalkConfig>): void
146
149
  }
package/types/event.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface EventPayloadMap {
9
9
  'editor-submit': undefined // 编辑器提交时
10
10
  'editor-submitted': undefined // 编辑器提交后
11
11
  'user-changed': LocalUser // 本地用户数据变更时
12
- 'conf-updated': undefined // Artalk 配置变更时
12
+ 'conf-loaded': undefined // Artalk 配置变更时
13
13
  'sidebar-show': undefined // 侧边栏显示
14
14
  'sidebar-hide': undefined // 侧边栏隐藏
15
15
  }