Commit b220828de34459b64cce8c82c59eebafb4791a62

Authored by ly525
1 parent 63a6b7b2

fix: page manager

front-end/h5/src/components/core/editor/left-panel/page-manager/index.js
1 1 import { mapState, mapActions } from 'vuex'
  2 +import PageTitleEditor from './title-editor'
  3 +import PageTitleMenu from './title-menu'
  4 +import PageTitleText from './title-text'
2 5  
3 6 export default {
4 7 data: () => ({
5   - hoverIndex: -1, // 显示编辑按钮
6   - editingTitle: '' // 临时缓存当前编辑的 title,点击 Yes 再真正用其更新 page title
  8 + hoverIndex: -1 // 显示编辑按钮
7 9 }),
8 10 computed: {
9 11 ...mapState('editor', {
... ... @@ -21,51 +23,14 @@ export default {
21 23 'saveWork',
22 24 'setEditingPage'
23 25 ]),
24   - getTitle (page, index) {
25   - return page.title || this.$t('editor.pageManager.title', { index })
  26 + onSelectMenuItem (menuKey) {
  27 + this.pageManager({ type: menuKey })
26 28 },
27   - _renderEditTitle (page, index) {
28   - return (
29   - <a-popconfirm
30   - placement="bottom"
31   - onConfirm={() => {
32   - this.$emit('editTitle', { newTitle: this.editingTitle, pageIndexForEditingTitle: index })
33   - }}
34   - onCancel={() => {}}
35   - okText="Yes"
36   - cancelText="No"
37   - >
38   - <a-input
39   - slot="title"
40   - value={this.editingTitle}
41   - size="small"
42   - onChange={e => {
43   - this.editingTitle = e.target.value
44   - }}
45   - >
46   - </a-input>
47   - <a-icon type="edit" onClick={(e) => {
48   - e.stopPropagation() // 将 click icon 与 click page item 隔离开。编辑标题的同时不要切换页面
49   - this.editingTitle = this.getTitle(page, index)
50   - }}/>
51   - </a-popconfirm>
52   - )
53   - },
54   - _renderTitleMenu (page, index) {
55   - const addPageText = this.$t('editor.pageManager.action.add')
56   - const copyPageText = this.$t('editor.pageManager.action.copy')
57   - const deletePageText = this.$t('editor.pageManager.action.delete')
58   - return (
59   - <a-dropdown trigger={['hover']} placement='bottomCenter'>
60   - <a class="ant-dropdown-link" href="#" class="ml-2"><a-icon type="down" /></a>
61   - <a-menu slot="overlay" onClick={({ key }) => this.$emit('selectMenuItem', key)}>
62   - <a-menu-item key="add"><a-icon type="plus" />{addPageText}</a-menu-item>
63   - <a-menu-item key="copy"><a-icon type="copy" />{copyPageText}</a-menu-item>
64   - <a-menu-item key="delete"><a-icon type="delete" />{deletePageText}</a-menu-item>
65   - </a-menu>
66   - </a-dropdown>
67   - )
  29 + onEditTitle ({ pageIndex, newTitle }) {
  30 + this.pageManager({ type: 'editTitle', value: { pageIndex, newTitle } })
  31 + this.saveWork({ isSaveCover: false })
68 32 },
  33 + onSelectPage (pageIndex) { this.setEditingPage(pageIndex) },
69 34 onLeave () {
70 35 this.hoverIndex = -1
71 36 }
... ... @@ -82,22 +47,21 @@ export default {
82 47 'page-manager-panel__item',
83 48 page.uuid === this.editingPage.uuid && 'active'
84 49 ]}
85   - onClick={() => { this.$emit('selectPage', index) }}
  50 + onClick={() => this.onSelectPage(index)}
86 51 // https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/components/VHover/VHover.ts
87 52 onMouseenter={() => { this.hoverIndex = index }}
88 53 >
89   - {/* #!en: Page<Index> */}
90   - {/* #!zh: 第<Index>页面 */}
91   - <span>
92   - <a-badge
93   - count={index + 1}
94   - numberStyle={{ backgroundColor: '#fff', color: '#999', boxShadow: '0 0 0 1px #d9d9d9 inset' }}
95   - />
96   - <span class="ml-3">{this.getTitle(page, index)}</span>
97   - </span>
  54 + <PageTitleText page={page} pageIndex={index} />
98 55 <span>
99   - {this.hoverIndex === index && this._renderEditTitle(page, index)}
100   - {this._renderTitleMenu(page, index)}
  56 + {
  57 + this.hoverIndex === index &&
  58 + <PageTitleEditor
  59 + page={page}
  60 + pageIndex={index}
  61 + onEditTitle={this.onEditTitle}
  62 + />
  63 + }
  64 + <PageTitleMenu onSelectMenuItem={this.onSelectMenuItem} />
101 65 </span>
102 66 </span>
103 67 ))
... ... @@ -106,7 +70,7 @@ export default {
106 70 icon="plus"
107 71 type="dashed"
108 72 class="footer-actions"
109   - onClick={() => { this.$emit('selectMenuItem', 'add') }}
  73 + onClick={() => this.onSelectMenuItem('add') }
110 74 >{addPageText}</a-button>
111 75 </div>
112 76 )
... ...
front-end/h5/src/components/core/editor/left-panel/page-manager/title-editor.js 0 → 100644
  1 +export default {
  2 + props: ['page', 'pageIndex'],
  3 + data: () => ({
  4 + editingTitle: '' // 临时缓存当前编辑的 title,点击 Yes 再真正用其更新 page title
  5 + }),
  6 + methods: {
  7 + getTitle () {
  8 + return this.page.title || this.$t('editor.pageManager.title', { index: this.pageIndex })
  9 + }
  10 + },
  11 + render () {
  12 + return (
  13 + <a-popconfirm
  14 + placement="bottom"
  15 + onConfirm={() => {
  16 + this.$emit('editTitle', { newTitle: this.editingTitle, pageIndex: this.pageIndex })
  17 + }}
  18 + onCancel={() => {}}
  19 + okText="Yes"
  20 + cancelText="No"
  21 + >
  22 + <a-input
  23 + slot="title"
  24 + value={this.editingTitle}
  25 + size="small"
  26 + onChange={e => {
  27 + this.editingTitle = e.target.value
  28 + }}
  29 + >
  30 + </a-input>
  31 + <a-icon type="edit" onClick={(e) => {
  32 + e.stopPropagation() // 将 click icon 与 click page item 隔离开。编辑标题的同时不要切换页面
  33 + this.editingTitle = this.getTitle()
  34 + }}/>
  35 + </a-popconfirm>
  36 +
  37 + )
  38 + }
  39 +}
... ...
front-end/h5/src/components/core/editor/left-panel/page-manager/title-menu.js 0 → 100644
  1 +export default {
  2 + render () {
  3 + const addPageText = this.$t('editor.pageManager.action.add')
  4 + const copyPageText = this.$t('editor.pageManager.action.copy')
  5 + const deletePageText = this.$t('editor.pageManager.action.delete')
  6 + return (
  7 + <a-dropdown trigger={['hover']} placement='bottomCenter'>
  8 + <a class="ant-dropdown-link" href="#" class="ml-2"><a-icon type="down" /></a>
  9 + <a-menu slot="overlay" onClick={({ key }) => this.$emit('selectMenuItem', key)}>
  10 + <a-menu-item key="add"><a-icon type="plus" />{addPageText}</a-menu-item>
  11 + <a-menu-item key="copy"><a-icon type="copy" />{copyPageText}</a-menu-item>
  12 + <a-menu-item key="delete"><a-icon type="delete" />{deletePageText}</a-menu-item>
  13 + </a-menu>
  14 + </a-dropdown>
  15 + )
  16 + }
  17 +}
... ...
front-end/h5/src/components/core/editor/left-panel/page-manager/title-text.js 0 → 100644
  1 +export default {
  2 + props: ['page', 'pageIndex'],
  3 + methods: {
  4 + getTitle () {
  5 + return this.page.title || this.$t('editor.pageManager.title', { index: this.pageIndex })
  6 + }
  7 + },
  8 + render (h) {
  9 + // #!en: Page<Index>
  10 + // #!zh: 第<Index>页面
  11 + return (
  12 + <span>
  13 + <a-badge
  14 + count={this.pageIndex + 1}
  15 + numberStyle={{ backgroundColor: '#fff', color: '#999', boxShadow: '0 0 0 1px #d9d9d9 inset' }}
  16 + />
  17 + <span class="ml-3">{this.getTitle()}</span>
  18 + </span>
  19 + )
  20 + }
  21 +}
... ...
front-end/h5/src/components/core/store/modules/page.js
... ... @@ -30,8 +30,8 @@ export const mutations = {
30 30 pageManager (state, { type, value }) {
31 31 switch (type) {
32 32 case 'editTitle':
33   - const { pageIndexForEditingTitle, newTitle } = value
34   - state.work.pages[pageIndexForEditingTitle].title = newTitle
  33 + const { pageIndex, newTitle } = value
  34 + state.work.pages[pageIndex].title = newTitle
35 35 break
36 36 case 'add':
37 37 const page = new Page(value)
... ...
front-end/h5/src/locales/lang/en-US.js
... ... @@ -70,6 +70,7 @@ export default {
70 70 redo: 'Redo{hotkey}',
71 71 preview: 'Preview',
72 72 copyCurrentPage: 'CopyCurrentPage',
  73 + copyCurrentElement: 'copyCurrentElement',
73 74 importPSD: 'Import PSD',
74 75 zoomIn: 'Zoom In{hotkey}',
75 76 zoomOut: 'Zoom Out{hotkey}',
... ...
front-end/h5/src/locales/lang/zh-CN.js
... ... @@ -2,8 +2,8 @@
2 2 * @Author: ly525
3 3 * @Date: 2019-11-24 18:51:58
4 4 * @LastEditors: ly525
5   - * @LastEditTime: 2020-04-18 00:30:40
6   - * @FilePath: /luban-h5/front-end/h5/src/locales/lang/zh-CN.js
  5 + * @LastEditTime: 2020-10-13 00:51:57
  6 + * @FilePath: /h5/src/locales/lang/zh-CN.js
7 7 * @Github: https://github.com/ly525/luban-h5
8 8 * @Description: Do not edit
9 9 * @Copyright 2018 - 2020 luban-h5. All Rights Reserved
... ... @@ -79,6 +79,7 @@ export default {
79 79 redo: '重做{hotkey}',
80 80 preview: '预览',
81 81 copyCurrentPage: '复制当前页面',
  82 + copyCurrentElement: '复制当前元素',
82 83 importPSD: '导入PSD',
83 84 zoomIn: '缩小{hotkey}',
84 85 zoomOut: '放大{hotkey}',
... ...