diff --git a/src/views/public/CommentGenerator.vue b/src/views/public/CommentGenerator.vue index 996140d..fa47405 100644 --- a/src/views/public/CommentGenerator.vue +++ b/src/views/public/CommentGenerator.vue @@ -4,10 +4,28 @@
评论生成(公开)
- - - - 刷新 +
+ + 全部 + {{ ltr }} + + 刷新 +
+
+
暂无数据
+
+
{{ ltr }}
+
+ {{ it.name }}({{ it.value }}) +
+
+
生成评论 @@ -27,11 +45,47 @@ export default { name: 'CommentGeneratorPublic', data() { - return { form: { productType: '' }, loading: false, result: null, typeOptions: [] } + return { form: { productType: '' }, loading: false, result: null, typeOptions: [], activeLetter: 'ALL' } }, computed: { pretty() { try { return this.result ? JSON.stringify(this.result, null, 2) : '' } catch(e) { return '' } + }, + letters() { + return Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ') + }, + groupedByLetter() { + const groups = {} + const items = Array.isArray(this.typeOptions) ? this.typeOptions.slice() : [] + items.forEach(it => { + const ltr = this.getInitial(it) + if (!groups[ltr]) groups[ltr] = [] + groups[ltr].push(it) + }) + Object.keys(groups).forEach(k => { + groups[k].sort((a, b) => { + const an = (a.name || '').toString() + const bn = (b.name || '').toString() + return an.localeCompare(bn) + }) + }) + return groups + }, + filteredGroups() { + if (this.activeLetter === 'ALL') { + const ordered = {} + this.letters.concat('#').forEach(l => { + if (this.groupedByLetter[l] && this.groupedByLetter[l].length) { + ordered[l] = this.groupedByLetter[l] + } + }) + if (this.groupedByLetter['#'] && !ordered['#']) ordered['#'] = this.groupedByLetter['#'] + return ordered + } + const letter = this.activeLetter + const res = {} + if (this.groupedByLetter[letter]) res[letter] = this.groupedByLetter[letter] + return res } }, mounted() { this.loadTypes() }, @@ -42,6 +96,18 @@ export default { if (res && (res.code === 200 || res.msg === '操作成功')) this.typeOptions = res.data || [] } catch(e) {} }, + getInitial(it) { + const source = (it && (it.value || it.name) || '').toString().trim() + if (!source) return '#' + const ch = source[0] + const upper = ch.toUpperCase() + if (upper >= 'A' && upper <= 'Z') return upper + return '#' + }, + selectType(it) { + if (!it) return + this.form.productType = it.value + }, async generate() { if (!this.form.productType) { this.$message.error('请选择型号'); return } this.loading = true @@ -70,6 +136,48 @@ export default {