|
| 1 | +import './gallery.scss' |
| 2 | +import PersonalTab from './tabs/personal.js' |
| 3 | +import PixabayTab from './tabs/pixabay.js' |
| 4 | + |
| 5 | +export default { |
| 6 | + components: { |
| 7 | + }, |
| 8 | + props: { |
| 9 | + visible: { |
| 10 | + type: Boolean, |
| 11 | + default: false |
| 12 | + }, |
| 13 | + value: { |
| 14 | + type: String, |
| 15 | + default: '' |
| 16 | + } |
| 17 | + }, |
| 18 | + data: () => ({ |
| 19 | + tabs: [ |
| 20 | + { |
| 21 | + value: 'personal', |
| 22 | + label: '我的图库' |
| 23 | + }, |
| 24 | + { |
| 25 | + value: 'pixabay', |
| 26 | + label: 'Pixabay图库' |
| 27 | + } |
| 28 | + ], |
| 29 | + activeTab: 'personal', |
| 30 | + innerVisible: false, |
| 31 | + pixabayList: [] |
| 32 | + }), |
| 33 | + computed: { |
| 34 | + }, |
| 35 | + watch: { |
| 36 | + visible (value) { |
| 37 | + this.innerVisible = value |
| 38 | + } |
| 39 | + }, |
| 40 | + methods: { |
| 41 | + handleClose () { |
| 42 | + this.innerVisible = false |
| 43 | + }, |
| 44 | + changeTab ({ key }) { |
| 45 | + this.activeTab = key |
| 46 | + }, |
| 47 | + handleSelectImage (item) { |
| 48 | + this.handleClose() |
| 49 | + this.$emit('change', item.previewURL) |
| 50 | + }, |
| 51 | + renderContent () { |
| 52 | + switch (this.activeTab) { |
| 53 | + case 'personal': |
| 54 | + return <PersonalTab onChangeItem={item => { |
| 55 | + this.handleSelectImage(item) |
| 56 | + }}/> |
| 57 | + case 'pixabay': |
| 58 | + return <PixabayTab onChange={item => { |
| 59 | + this.handleSelectImage(item) |
| 60 | + }}/> |
| 61 | + } |
| 62 | + }, |
| 63 | + renderDefaultActivator () { |
| 64 | + const activatorWithoutImg = ( |
| 65 | + <div |
| 66 | + class="default-activator cursor-pointer " |
| 67 | + onClick={() => { this.innerVisible = true }} |
| 68 | + > |
| 69 | + <a-icon type="plus" /> |
| 70 | + </div> |
| 71 | + ) |
| 72 | + |
| 73 | + const activatorWithImg = ( |
| 74 | + <div |
| 75 | + class="default-activator cursor-pointer " |
| 76 | + onClick={() => { this.innerVisible = true }} |
| 77 | + > |
| 78 | + <img src={this.value} style={{ width: '100%' }} /> |
| 79 | + <div class="flex-space-between" style="margin-top: 8px;"> |
| 80 | + <a-button>更换图片</a-button> |
| 81 | + <a-button onClick={e => { |
| 82 | + e.stopPropagation() |
| 83 | + }}>裁剪图片</a-button> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + ) |
| 87 | + return (this.value ? activatorWithImg : activatorWithoutImg) |
| 88 | + } |
| 89 | + }, |
| 90 | + render (h) { |
| 91 | + return ( |
| 92 | + <div> |
| 93 | + <slot>{this.renderDefaultActivator()}</slot> |
| 94 | + <a-modal |
| 95 | + closable |
| 96 | + title="图片库" |
| 97 | + width="65%" |
| 98 | + visible={this.innerVisible} |
| 99 | + onOk={this.handleClose} |
| 100 | + onCancel={this.handleClose} |
| 101 | + bodyStyle={{ margin: 0, padding: 0 }} |
| 102 | + > |
| 103 | + <a-layout style="height: 500px; position: relative;"> |
| 104 | + <a-layout-sider width="200px" style="background-color: white;"> |
| 105 | + <a-menu mode="inline" defaultSelectedKeys={['personal']} onClick={this.changeTab}> |
| 106 | + { |
| 107 | + this.tabs.map((tab, index) => ( |
| 108 | + <a-menu-item key={tab.value} > |
| 109 | + <a-icon type="user" /> |
| 110 | + <span>{tab.label}</span> |
| 111 | + </a-menu-item> |
| 112 | + )) |
| 113 | + } |
| 114 | + </a-menu> |
| 115 | + </a-layout-sider> |
| 116 | + <a-layout-content> |
| 117 | + {this.renderContent()} |
| 118 | + </a-layout-content> |
| 119 | + </a-layout> |
| 120 | + </a-modal> |
| 121 | + </div> |
| 122 | + ) |
| 123 | + } |
| 124 | +} |
0 commit comments