Commit 816ce3ae202eb8ef6d6acc1185ce6e12038fe5d7
1 parent
18f9081a
feat(work): delete work; #!zh: 支持删除作品
Showing
7 changed files
with
57 additions
and
15 deletions
front-end/h5/src/components/core/store/modules/loading.js
front-end/h5/src/locales/lang/en-US.js
| ... | ... | @@ -22,8 +22,10 @@ export default { |
| 22 | 22 | useNow: 'Use it Now', |
| 23 | 23 | preview: 'Preview', |
| 24 | 24 | edit: 'Edit', |
| 25 | + delete: 'Delete', | |
| 25 | 26 | createNewWork: 'Create New', |
| 26 | - view: 'View Work' | |
| 27 | + view: 'View Work', | |
| 28 | + confirmDeleteTip: 'Confirm Delete {tip}?' | |
| 27 | 29 | }, |
| 28 | 30 | basicData: { |
| 29 | 31 | viewData: 'View Data' | ... | ... |
front-end/h5/src/locales/lang/zh-CN.js
front-end/h5/src/store/modules/work.js
| ... | ... | @@ -50,6 +50,16 @@ export const actions = { |
| 50 | 50 | // router.replace({ name: 'editor', params: { workId: entry.id } }) |
| 51 | 51 | }).catch(handleError) |
| 52 | 52 | }, |
| 53 | + deleteWork ({ commit, dispatch, state }, workId) { | |
| 54 | + return new AxiosWrapper({ | |
| 55 | + dispatch, | |
| 56 | + commit, | |
| 57 | + loading_name: 'deleteWork_loading', | |
| 58 | + successMsg: '删除作品成功', | |
| 59 | + customRequest: strapi.deleteEntry.bind(strapi) | |
| 60 | + }).delete('works', workId).catch(handleError) | |
| 61 | + // return strapi.deleteEntry('works', workId) | |
| 62 | + }, | |
| 53 | 63 | updateWork ({ commit, state }, payload = {}) { |
| 54 | 64 | // update work with strapi |
| 55 | 65 | const work = { | ... | ... |
front-end/h5/src/utils/http.js
| ... | ... | @@ -98,6 +98,14 @@ export class AxiosWrapper { |
| 98 | 98 | this.setDefaultLoadingName(args) |
| 99 | 99 | |
| 100 | 100 | this.setLoadingValue(true) |
| 101 | + if (this.customRequest) { | |
| 102 | + return this.customRequest(...args) | |
| 103 | + .then(data => { | |
| 104 | + const handler = this.getCommonResponseHandler({ failMsg: 'Save Failed.' }) | |
| 105 | + handler.call(this, { status: 200, data: { data } }) | |
| 106 | + }) | |
| 107 | + .finally(() => this.setLoadingValue(false)) | |
| 108 | + } | |
| 101 | 109 | return this.instance.delete(...args).then(response => { |
| 102 | 110 | const handler = this.getCommonResponseHandler({ failMsg: 'Save Failed.' }) |
| 103 | 111 | handler.call(this, response) | ... | ... |
front-end/h5/src/views/work-manager/list.vue
| ... | ... | @@ -24,6 +24,9 @@ const ListItemCard = { |
| 24 | 24 | qrcodeUrl: '' |
| 25 | 25 | }), |
| 26 | 26 | methods: { |
| 27 | + ...mapActions('editor', [ | |
| 28 | + 'deleteWork' | |
| 29 | + ]), | |
| 27 | 30 | timeFmt (date) { |
| 28 | 31 | const dateTime = new Date(date) |
| 29 | 32 | const displayTime = `${dateTime.getFullYear()}-${dateTime.getMonth() + |
| ... | ... | @@ -36,6 +39,20 @@ const ListItemCard = { |
| 36 | 39 | if (err) console.log(err) |
| 37 | 40 | this.qrcodeUrl = url |
| 38 | 41 | }) |
| 42 | + }, | |
| 43 | + handleDeleteWork () { | |
| 44 | + const { title, id } = this.work | |
| 45 | + this.$confirm({ | |
| 46 | + title: this.$t('workCard.confirmDeleteTip', { tip: `${title}(${id})` }), | |
| 47 | + // content: 'Bla bla ...', | |
| 48 | + okText: 'Confirm', | |
| 49 | + cancelText: 'Cancel', | |
| 50 | + onOk: async () => { | |
| 51 | + await this.deleteWork(this.work.id) | |
| 52 | + this.$emit('deleteSuccess') | |
| 53 | + }, | |
| 54 | + onCancel: () => {} | |
| 55 | + }) | |
| 39 | 56 | } |
| 40 | 57 | }, |
| 41 | 58 | render (h) { |
| ... | ... | @@ -53,6 +70,10 @@ const ListItemCard = { |
| 53 | 70 | <a-tooltip effect="dark" placement="bottom" title={this.$t('workCard.preview')}> |
| 54 | 71 | <a-icon type="eye" title={this.$t('workCard.preview')} onClick={this.handleClickPreview} /> |
| 55 | 72 | </a-tooltip> |
| 73 | + {/** 删除 */} | |
| 74 | + <a-tooltip effect="dark" placement="bottom" title={this.$t('workCard.delete')}> | |
| 75 | + <a-icon type="delete" title={this.$t('workCard.delete')} onClick={this.handleDeleteWork} /> | |
| 76 | + </a-tooltip> | |
| 56 | 77 | { |
| 57 | 78 | this.qrcodeUrl |
| 58 | 79 | ? <a-icon type="close-circle" onClick={() => { this.qrcodeUrl = '' }} /> |
| ... | ... | @@ -114,10 +135,7 @@ export default { |
| 114 | 135 | ...mapActions('editor', [ |
| 115 | 136 | 'fetchWorks', |
| 116 | 137 | 'createWork' |
| 117 | - ]), | |
| 118 | - deleteWork (item) { | |
| 119 | - // TODO delete work from work list | |
| 120 | - } | |
| 138 | + ]) | |
| 121 | 139 | }, |
| 122 | 140 | render (h) { |
| 123 | 141 | return ( |
| ... | ... | @@ -133,10 +151,14 @@ export default { |
| 133 | 151 | </a-col> |
| 134 | 152 | : this.works.map(work => ( |
| 135 | 153 | <a-col span={6} key={work.id} style="margin-bottom: 20px;"> |
| 136 | - <ListItemCard work={work} handleClickPreview={e => { | |
| 137 | - this.previewVisible = true | |
| 138 | - this.activeWork = work | |
| 139 | - }} /> | |
| 154 | + <ListItemCard | |
| 155 | + work={work} | |
| 156 | + handleClickPreview={e => { | |
| 157 | + this.previewVisible = true | |
| 158 | + this.activeWork = work | |
| 159 | + }} | |
| 160 | + onDeleteSuccess={this.fetchWorks} | |
| 161 | + /> | |
| 140 | 162 | </a-col> |
| 141 | 163 | )) |
| 142 | 164 | } | ... | ... |
front-end/h5/src/views/work-manager/templates.vue