Commit 816ce3ae202eb8ef6d6acc1185ce6e12038fe5d7

Authored by ly525
1 parent 18f9081a

feat(work): delete work; #!zh: 支持删除作品

front-end/h5/src/components/core/store/modules/loading.js
@@ -16,7 +16,8 @@ const state = { @@ -16,7 +16,8 @@ const state = {
16 setWorkAsTemplate_loading: false, 16 setWorkAsTemplate_loading: false,
17 fetchWorkTemplates_loading: false, 17 fetchWorkTemplates_loading: false,
18 useTemplate_loading: false, 18 useTemplate_loading: false,
19 - uploadWorkCover_loading: false 19 + uploadWorkCover_loading: false,
  20 + deleteWork_loading: false
20 } 21 }
21 22
22 // getters 23 // getters
front-end/h5/src/locales/lang/en-US.js
@@ -22,8 +22,10 @@ export default { @@ -22,8 +22,10 @@ export default {
22 useNow: 'Use it Now', 22 useNow: 'Use it Now',
23 preview: 'Preview', 23 preview: 'Preview',
24 edit: 'Edit', 24 edit: 'Edit',
  25 + delete: 'Delete',
25 createNewWork: 'Create New', 26 createNewWork: 'Create New',
26 - view: 'View Work' 27 + view: 'View Work',
  28 + confirmDeleteTip: 'Confirm Delete {tip}?'
27 }, 29 },
28 basicData: { 30 basicData: {
29 viewData: 'View Data' 31 viewData: 'View Data'
front-end/h5/src/locales/lang/zh-CN.js
@@ -33,7 +33,9 @@ export default { @@ -33,7 +33,9 @@ export default {
33 preview: '预览', 33 preview: '预览',
34 createNewWork: '创建新作品', 34 createNewWork: '创建新作品',
35 edit: '编辑', 35 edit: '编辑',
36 - view: '查看作品' 36 + delete: '删除',
  37 + view: '查看作品',
  38 + confirmDeleteTip: '确认删除 {tip}?'
37 }, 39 },
38 basicData: { 40 basicData: {
39 viewData: '查看数据' 41 viewData: '查看数据'
front-end/h5/src/store/modules/work.js
@@ -50,6 +50,16 @@ export const actions = { @@ -50,6 +50,16 @@ export const actions = {
50 // router.replace({ name: 'editor', params: { workId: entry.id } }) 50 // router.replace({ name: 'editor', params: { workId: entry.id } })
51 }).catch(handleError) 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 updateWork ({ commit, state }, payload = {}) { 63 updateWork ({ commit, state }, payload = {}) {
54 // update work with strapi 64 // update work with strapi
55 const work = { 65 const work = {
front-end/h5/src/utils/http.js
@@ -98,6 +98,14 @@ export class AxiosWrapper { @@ -98,6 +98,14 @@ export class AxiosWrapper {
98 this.setDefaultLoadingName(args) 98 this.setDefaultLoadingName(args)
99 99
100 this.setLoadingValue(true) 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 return this.instance.delete(...args).then(response => { 109 return this.instance.delete(...args).then(response => {
102 const handler = this.getCommonResponseHandler({ failMsg: 'Save Failed.' }) 110 const handler = this.getCommonResponseHandler({ failMsg: 'Save Failed.' })
103 handler.call(this, response) 111 handler.call(this, response)
front-end/h5/src/views/work-manager/list.vue
@@ -24,6 +24,9 @@ const ListItemCard = { @@ -24,6 +24,9 @@ const ListItemCard = {
24 qrcodeUrl: '' 24 qrcodeUrl: ''
25 }), 25 }),
26 methods: { 26 methods: {
  27 + ...mapActions('editor', [
  28 + 'deleteWork'
  29 + ]),
27 timeFmt (date) { 30 timeFmt (date) {
28 const dateTime = new Date(date) 31 const dateTime = new Date(date)
29 const displayTime = `${dateTime.getFullYear()}-${dateTime.getMonth() + 32 const displayTime = `${dateTime.getFullYear()}-${dateTime.getMonth() +
@@ -36,6 +39,20 @@ const ListItemCard = { @@ -36,6 +39,20 @@ const ListItemCard = {
36 if (err) console.log(err) 39 if (err) console.log(err)
37 this.qrcodeUrl = url 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 render (h) { 58 render (h) {
@@ -53,6 +70,10 @@ const ListItemCard = { @@ -53,6 +70,10 @@ const ListItemCard = {
53 <a-tooltip effect="dark" placement="bottom" title={this.$t('workCard.preview')}> 70 <a-tooltip effect="dark" placement="bottom" title={this.$t('workCard.preview')}>
54 <a-icon type="eye" title={this.$t('workCard.preview')} onClick={this.handleClickPreview} /> 71 <a-icon type="eye" title={this.$t('workCard.preview')} onClick={this.handleClickPreview} />
55 </a-tooltip> 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 this.qrcodeUrl 78 this.qrcodeUrl
58 ? <a-icon type="close-circle" onClick={() => { this.qrcodeUrl = '' }} /> 79 ? <a-icon type="close-circle" onClick={() => { this.qrcodeUrl = '' }} />
@@ -114,10 +135,7 @@ export default { @@ -114,10 +135,7 @@ export default {
114 ...mapActions('editor', [ 135 ...mapActions('editor', [
115 'fetchWorks', 136 'fetchWorks',
116 'createWork' 137 'createWork'
117 - ]),  
118 - deleteWork (item) {  
119 - // TODO delete work from work list  
120 - } 138 + ])
121 }, 139 },
122 render (h) { 140 render (h) {
123 return ( 141 return (
@@ -133,10 +151,14 @@ export default { @@ -133,10 +151,14 @@ export default {
133 </a-col> 151 </a-col>
134 : this.works.map(work => ( 152 : this.works.map(work => (
135 <a-col span={6} key={work.id} style="margin-bottom: 20px;"> 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 </a-col> 162 </a-col>
141 )) 163 ))
142 } 164 }
front-end/h5/src/views/work-manager/templates.vue
@@ -101,10 +101,7 @@ export default { @@ -101,10 +101,7 @@ export default {
101 'fetchWorks', 101 'fetchWorks',
102 'fetchWorkTemplates', 102 'fetchWorkTemplates',
103 'useTemplate' 103 'useTemplate'
104 - ]),  
105 - deleteWork (item) {  
106 - // TODO delete work from work list  
107 - } 104 + ])
108 }, 105 },
109 render (h) { 106 render (h) {
110 return ( 107 return (