vue2-client 1.8.67 → 1.8.69

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.
@@ -1,280 +1,280 @@
1
- <template>
2
- <a-card class="question-history" id="question-history" size="small" :bordered="false" :bodyStyle="{ height:'100%', overflowY: 'auto'}">
3
- <a-tabs v-model="activeKey" :tabBarStyle="{ textAlign: 'center',height:'100%',postion:'' }" tabPosition="top">
4
- <a-tab-pane key="1" tab="对话历史">
5
- <a-list item-layout="horizontal" :data-source="questions">
6
- <a-list-item
7
- slot="renderItem"
8
- :class="item.uuid === currentuuid ? 'question-history-active' : 'question-history-inactive'"
9
- slot-scope="item,index"
10
- @click="handleOpenFavorite(item)">
11
- <a-list-item-meta
12
- :title="item.question"
13
- :description="item.date"
14
- />
15
- <a-space>
16
- <a-icon
17
- type="delete"
18
- theme="filled"
19
- class="delClass"
20
- @click.stop="delQuestion(item,index)"
21
- />
22
- <span>&emsp;</span>
23
- <a-icon
24
- v-if="item.data"
25
- type="star"
26
- :class="item.isFavorite ? 'startActive' : 'startInactive'"
27
- @click.stop="toFavorites(item,index)"
28
- :theme=" item.isFavorite ? 'filled': 'twoTone'"
29
- two-tone-color="#FFD700"/>
30
- <a-icon
31
- v-else
32
- @click.stop="reTrySearch(item)"
33
- type="sync"
34
- class="reSearch"
35
- title="重新查询"/>
36
- </a-space>
37
- </a-list-item>
38
- </a-list>
39
- </a-tab-pane>
40
- <a-tab-pane key="2" tab="收藏的对话" force-render>
41
- <a-list item-layout="horizontal" :data-source="favorites">
42
- <a-list-item
43
- slot="renderItem"
44
- slot-scope="item, index"
45
- :class="item.uuid === currentuuid ? 'question-history-active' : 'question-history-inactive'"
46
- @click="handleOpenFavorite(item)">
47
- <a-list-item-meta
48
- :title="item.question"
49
- :description="item.date"
50
- />
51
- <a-space>
52
- <a-icon
53
- type="star"
54
- :class="item.isFavorite ? 'startActive' : 'startInactive'"
55
- @click.stop="delFavorites(item,index)"
56
- :theme=" item.isFavorite ? 'filled': 'twoTone'"
57
- two-tone-color="#FFD700"/>
58
- </a-space>
59
- </a-list-item>
60
- </a-list>
61
- </a-tab-pane>
62
- </a-tabs>
63
- </a-card>
64
- </template>
65
-
66
- <script>
67
- import { indexedDB } from '@vue2-client/utils/indexedDB'
68
- import { formatDate } from '@vue2-client/utils/util'
69
-
70
- export default {
71
- props: {
72
- currentuuid: {
73
- type: String,
74
- default: ''
75
- }
76
- },
77
- data () {
78
- return {
79
- activeKey: '1',
80
- questions: [], // 你的问题历史
81
- favorites: [] // 你的收藏问题
82
- }
83
- },
84
- mounted () {
85
- this.loadData()
86
- },
87
- methods: {
88
- loadData () {
89
- indexedDB.getAll((data) => {
90
- // 遍历data,将question和favorites分别赋值给questions和favorites
91
- for (const datum of data) {
92
- if (datum.key.includes('question')) {
93
- this.questions.push(datum.data)
94
- } else if (datum.key.includes('favorites')) {
95
- this.favorites.push(datum.data)
96
- }
97
- }
98
- }
99
- )
100
- },
101
- handleOpenFavorite (item) {
102
- this.$emit('handleOpenFavorite', item)
103
- },
104
- reTrySearch (item) {
105
- this.$emit('handleSearch', item.question, null, item.uuid)
106
- },
107
- add (question) {
108
- // 检查 questions 数组中是否已经存在这个问题 替换掉
109
- const index = this.questions.findIndex(item => item.uuid === question.uuid)
110
- if (index !== -1) {
111
- if (question.data) {
112
- this.questions.splice(index, 1, Object.assign(question, { date: this.questions[index].date }))
113
- } else {
114
- this.questions.splice(index, 1, question)
115
- }
116
- this.updateQuestion(question)
117
- return
118
- }
119
- this.questions.push(question)
120
- indexedDB.add('question-' + question.uuid, question)
121
- },
122
- updateQuestion (question) {
123
- const questionKey = 'question-' + question.uuid
124
- indexedDB.delete(questionKey)
125
- indexedDB.add(questionKey, question)
126
- },
127
-
128
- toFavorites (question, index) {
129
- this.questions[index].isFavorite = !this.questions[index].isFavorite
130
- if (this.questions[index].isFavorite) {
131
- const key = 'favorites-' + question.uuid
132
- question.date = formatDate('now')
133
- question.isFavorite = true
134
- indexedDB.add(key, question)
135
- this.favorites.push(question)
136
- this.$message.success('收藏成功')
137
- } else {
138
- // 根据 uuid 删除 favorites 中的对应项
139
- this.favorites = this.favorites.filter(item => item.uuid !== question.uuid)
140
- // 删除收藏的储存
141
- const key = 'favorites-' + question.uuid
142
- indexedDB.delete(key)
143
- }
144
- this.updateQuestion(question)
145
- },
146
- delQuestion (item, index) {
147
- // 删除对话历史
148
- this.questions.splice(index, 1)
149
- const key = 'question-' + item.uuid
150
- indexedDB.delete(key)
151
- // 删除收藏
152
- const favoritesKey = 'favorites-' + item.uuid
153
- indexedDB.delete(favoritesKey)
154
- // 删除收藏数组中的对应项
155
- this.favorites = this.favorites.filter(favorite => favorite.uuid !== item.uuid)
156
- this.$message.success('删除成功')
157
- },
158
- delFavorites (item, index) {
159
- this.favorites.splice(index, 1)
160
- // 根据uuid寻找 questions 中的对应项
161
- // 重新赋值给 questions
162
- this.questions = this.questions.map(_item => {
163
- if (_item.uuid === item.uuid) {
164
- _item.isFavorite = false
165
- }
166
- return _item
167
- })
168
- const key = 'favorites-' + item.uuid
169
- indexedDB.delete(key)
170
- this.$message.success('取消收藏成功')
171
- // 如果favorites为空,切换到对话历史
172
- if (this.favorites.length === 0) {
173
- this.activeKey = '1'
174
- }
175
- this.updateQuestion(item)
176
- }
177
- ,
178
- }
179
- }
180
- </script>
181
-
182
- <style scoped lang="less">
183
-
184
- #question-history {
185
-
186
- margin-right: 10px;
187
- height: 100%;
188
- border-radius: 8px;
189
-
190
- .question-history-active {
191
- border-left: 4px solid #1890FF;
192
- // 左上左下圆角
193
- border-radius: 4px 0 0 4px;
194
- padding-left : 14px;
195
- }
196
-
197
- .question-history-inactive {
198
- padding-left : 18px;
199
- }
200
-
201
- .ant-list-item-meta /deep/ {
202
- width: 60%;
203
- }
204
-
205
- .ant-list-item-meta-content /deep/ {
206
- width: 98%;
207
- }
208
-
209
- .ant-list-item-meta-title /deep/ {
210
- width: 90%;
211
- white-space: nowrap;
212
- overflow: hidden;
213
- text-overflow: ellipsis;
214
- }
215
-
216
- .ant-card {
217
- height: 100%;
218
- overflow-y: auto;
219
- }
220
-
221
- .startActive {
222
- color: #FFD700;
223
- font-size: 1rem;
224
- }
225
-
226
- .startInactive {
227
- font-size: 1rem;
228
- }
229
-
230
- .delClass {
231
- font-size: 1rem;
232
- color: #777;
233
- }
234
-
235
- .reSearch {
236
- font-size: 1rem;
237
- color: #1890FF;
238
- }
239
-
240
- .reSearch:hover {
241
- animation: rotate 0.5s ease-in-out both;
242
- }
243
-
244
- @keyframes rotate {
245
- 0% {
246
- transform: rotate(0deg);
247
- }
248
- 100% {
249
- transform: rotate(180deg);
250
- }
251
- }
252
-
253
- .startActive, .startInactive, .reSearch {
254
- transition: transform 0.1s;
255
- }
256
-
257
- .startActive:hover, .startInactive:hover {
258
- animation: shake 0.5s ease-in-out both;
259
- }
260
-
261
- @keyframes shake {
262
- 0% {
263
- transform: rotate(0deg);
264
- }
265
- 25% {
266
- transform: rotate(-20deg);
267
- }
268
- 50% {
269
- transform: rotate(0deg);
270
- }
271
- 75% {
272
- transform: rotate(20deg);
273
- }
274
- 100% {
275
- transform: rotate(0deg);
276
- }
277
- }
278
- }
279
-
280
- </style>
1
+ <template>
2
+ <a-card class="question-history" id="question-history" size="small" :bordered="false" :bodyStyle="{ height:'100%', overflowY: 'auto'}">
3
+ <a-tabs v-model="activeKey" :tabBarStyle="{ textAlign: 'center',height:'100%',postion:'' }" tabPosition="top">
4
+ <a-tab-pane key="1" tab="对话历史">
5
+ <a-list item-layout="horizontal" :data-source="questions">
6
+ <a-list-item
7
+ slot="renderItem"
8
+ :class="item.uuid === currentuuid ? 'question-history-active' : 'question-history-inactive'"
9
+ slot-scope="item,index"
10
+ @click="handleOpenFavorite(item)">
11
+ <a-list-item-meta
12
+ :title="item.question"
13
+ :description="item.date"
14
+ />
15
+ <a-space>
16
+ <a-icon
17
+ type="delete"
18
+ theme="filled"
19
+ class="delClass"
20
+ @click.stop="delQuestion(item,index)"
21
+ />
22
+ <span>&emsp;</span>
23
+ <a-icon
24
+ v-if="item.data"
25
+ type="star"
26
+ :class="item.isFavorite ? 'startActive' : 'startInactive'"
27
+ @click.stop="toFavorites(item,index)"
28
+ :theme=" item.isFavorite ? 'filled': 'twoTone'"
29
+ two-tone-color="#FFD700"/>
30
+ <a-icon
31
+ v-else
32
+ @click.stop="reTrySearch(item)"
33
+ type="sync"
34
+ class="reSearch"
35
+ title="重新查询"/>
36
+ </a-space>
37
+ </a-list-item>
38
+ </a-list>
39
+ </a-tab-pane>
40
+ <a-tab-pane key="2" tab="收藏的对话" force-render>
41
+ <a-list item-layout="horizontal" :data-source="favorites">
42
+ <a-list-item
43
+ slot="renderItem"
44
+ slot-scope="item, index"
45
+ :class="item.uuid === currentuuid ? 'question-history-active' : 'question-history-inactive'"
46
+ @click="handleOpenFavorite(item)">
47
+ <a-list-item-meta
48
+ :title="item.question"
49
+ :description="item.date"
50
+ />
51
+ <a-space>
52
+ <a-icon
53
+ type="star"
54
+ :class="item.isFavorite ? 'startActive' : 'startInactive'"
55
+ @click.stop="delFavorites(item,index)"
56
+ :theme=" item.isFavorite ? 'filled': 'twoTone'"
57
+ two-tone-color="#FFD700"/>
58
+ </a-space>
59
+ </a-list-item>
60
+ </a-list>
61
+ </a-tab-pane>
62
+ </a-tabs>
63
+ </a-card>
64
+ </template>
65
+
66
+ <script>
67
+ import { indexedDB } from '@vue2-client/utils/indexedDB'
68
+ import { formatDate } from '@vue2-client/utils/util'
69
+
70
+ export default {
71
+ props: {
72
+ currentuuid: {
73
+ type: String,
74
+ default: ''
75
+ }
76
+ },
77
+ data () {
78
+ return {
79
+ activeKey: '1',
80
+ questions: [], // 你的问题历史
81
+ favorites: [] // 你的收藏问题
82
+ }
83
+ },
84
+ mounted () {
85
+ this.loadData()
86
+ },
87
+ methods: {
88
+ loadData () {
89
+ indexedDB.getAll((data) => {
90
+ // 遍历data,将question和favorites分别赋值给questions和favorites
91
+ for (const datum of data) {
92
+ if (datum.key.includes('question')) {
93
+ this.questions.push(datum.data)
94
+ } else if (datum.key.includes('favorites')) {
95
+ this.favorites.push(datum.data)
96
+ }
97
+ }
98
+ }
99
+ )
100
+ },
101
+ handleOpenFavorite (item) {
102
+ this.$emit('handleOpenFavorite', item)
103
+ },
104
+ reTrySearch (item) {
105
+ this.$emit('handleSearch', item.question, null, item.uuid)
106
+ },
107
+ add (question) {
108
+ // 检查 questions 数组中是否已经存在这个问题 替换掉
109
+ const index = this.questions.findIndex(item => item.uuid === question.uuid)
110
+ if (index !== -1) {
111
+ if (question.data) {
112
+ this.questions.splice(index, 1, Object.assign(question, { date: this.questions[index].date }))
113
+ } else {
114
+ this.questions.splice(index, 1, question)
115
+ }
116
+ this.updateQuestion(question)
117
+ return
118
+ }
119
+ this.questions.push(question)
120
+ indexedDB.add('question-' + question.uuid, question)
121
+ },
122
+ updateQuestion (question) {
123
+ const questionKey = 'question-' + question.uuid
124
+ indexedDB.delete(questionKey)
125
+ indexedDB.add(questionKey, question)
126
+ },
127
+
128
+ toFavorites (question, index) {
129
+ this.questions[index].isFavorite = !this.questions[index].isFavorite
130
+ if (this.questions[index].isFavorite) {
131
+ const key = 'favorites-' + question.uuid
132
+ question.date = formatDate('now')
133
+ question.isFavorite = true
134
+ indexedDB.add(key, question)
135
+ this.favorites.push(question)
136
+ this.$message.success('收藏成功')
137
+ } else {
138
+ // 根据 uuid 删除 favorites 中的对应项
139
+ this.favorites = this.favorites.filter(item => item.uuid !== question.uuid)
140
+ // 删除收藏的储存
141
+ const key = 'favorites-' + question.uuid
142
+ indexedDB.delete(key)
143
+ }
144
+ this.updateQuestion(question)
145
+ },
146
+ delQuestion (item, index) {
147
+ // 删除对话历史
148
+ this.questions.splice(index, 1)
149
+ const key = 'question-' + item.uuid
150
+ indexedDB.delete(key)
151
+ // 删除收藏
152
+ const favoritesKey = 'favorites-' + item.uuid
153
+ indexedDB.delete(favoritesKey)
154
+ // 删除收藏数组中的对应项
155
+ this.favorites = this.favorites.filter(favorite => favorite.uuid !== item.uuid)
156
+ this.$message.success('删除成功')
157
+ },
158
+ delFavorites (item, index) {
159
+ this.favorites.splice(index, 1)
160
+ // 根据uuid寻找 questions 中的对应项
161
+ // 重新赋值给 questions
162
+ this.questions = this.questions.map(_item => {
163
+ if (_item.uuid === item.uuid) {
164
+ _item.isFavorite = false
165
+ }
166
+ return _item
167
+ })
168
+ const key = 'favorites-' + item.uuid
169
+ indexedDB.delete(key)
170
+ this.$message.success('取消收藏成功')
171
+ // 如果favorites为空,切换到对话历史
172
+ if (this.favorites.length === 0) {
173
+ this.activeKey = '1'
174
+ }
175
+ this.updateQuestion(item)
176
+ }
177
+ ,
178
+ }
179
+ }
180
+ </script>
181
+
182
+ <style scoped lang="less">
183
+
184
+ #question-history {
185
+
186
+ margin-right: 10px;
187
+ height: 100%;
188
+ border-radius: 8px;
189
+
190
+ .question-history-active {
191
+ border-left: 4px solid #1890FF;
192
+ // 左上左下圆角
193
+ border-radius: 4px 0 0 4px;
194
+ padding-left : 14px;
195
+ }
196
+
197
+ .question-history-inactive {
198
+ padding-left : 18px;
199
+ }
200
+
201
+ .ant-list-item-meta /deep/ {
202
+ width: 60%;
203
+ }
204
+
205
+ .ant-list-item-meta-content /deep/ {
206
+ width: 98%;
207
+ }
208
+
209
+ .ant-list-item-meta-title /deep/ {
210
+ width: 90%;
211
+ white-space: nowrap;
212
+ overflow: hidden;
213
+ text-overflow: ellipsis;
214
+ }
215
+
216
+ .ant-card {
217
+ height: 100%;
218
+ overflow-y: auto;
219
+ }
220
+
221
+ .startActive {
222
+ color: #FFD700;
223
+ font-size: 1rem;
224
+ }
225
+
226
+ .startInactive {
227
+ font-size: 1rem;
228
+ }
229
+
230
+ .delClass {
231
+ font-size: 1rem;
232
+ color: #777;
233
+ }
234
+
235
+ .reSearch {
236
+ font-size: 1rem;
237
+ color: #1890FF;
238
+ }
239
+
240
+ .reSearch:hover {
241
+ animation: rotate 0.5s ease-in-out both;
242
+ }
243
+
244
+ @keyframes rotate {
245
+ 0% {
246
+ transform: rotate(0deg);
247
+ }
248
+ 100% {
249
+ transform: rotate(180deg);
250
+ }
251
+ }
252
+
253
+ .startActive, .startInactive, .reSearch {
254
+ transition: transform 0.1s;
255
+ }
256
+
257
+ .startActive:hover, .startInactive:hover {
258
+ animation: shake 0.5s ease-in-out both;
259
+ }
260
+
261
+ @keyframes shake {
262
+ 0% {
263
+ transform: rotate(0deg);
264
+ }
265
+ 25% {
266
+ transform: rotate(-20deg);
267
+ }
268
+ 50% {
269
+ transform: rotate(0deg);
270
+ }
271
+ 75% {
272
+ transform: rotate(20deg);
273
+ }
274
+ 100% {
275
+ transform: rotate(0deg);
276
+ }
277
+ }
278
+ }
279
+
280
+ </style>