king
2024-08-25 326aa6b3effaccc71cfe0775d47b0f29eb3695a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import React, {Component} from 'react'
import { Modal, Button, Row, Col, Input, message, Tabs, Empty, Pagination, notification, Typography } from 'antd'
import { PlusOutlined, CopyOutlined, EditOutlined, DeleteOutlined, PictureOutlined } from '@ant-design/icons'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import { minkeIconSystem } from '@/utils/option.js'
import MkIcon from '@/components/mk-icon'
import './index.scss'
 
const { Search } = Input
const { confirm } = Modal
const { TabPane } = Tabs
const { Paragraph } = Typography
 
const EditForm = asyncComponent(() => import('./editform'))
const Video = asyncComponent(() => import('./video'))
const Image = asyncComponent(() => import('@/components/Image'))
 
class SourceController extends Component {
  state = {
    visible: false,
    editvisible: false,
    pictures: [],
    imageKey: '',
    videoKey: '',
    videos: [],
    card: null,
    pageSize: 12,
    filpictures: [],
    filvideos: [],
    colorlist: [],
    piclist: [],
    vidlist: [],
    iconlist: [...minkeIconSystem.direction, ...minkeIconSystem.edit, ...minkeIconSystem.normal, ...minkeIconSystem.data, ...minkeIconSystem.hint],
    picIndex: 1,
    vidIndex: 1,
  }
 
  trigger = () => {
    let deffers = []
 
    deffers.push(this.getSource('image', 'app_pictures', 0))
    deffers.push(this.getSource('video', 'app_videos', 50))
    deffers.push(this.getSource('color', 'app_colors', 100))
    
    Promise.all(deffers).then(result => {
      this.open(...result)
    })
  }
 
  getSource = (type, sessionName, delay) => {
    return new Promise(resolve => {
      if (window.GLOB[sessionName]) {
        resolve(window.GLOB[sessionName])
      } else {
        let param = {
          func: 's_url_db_adduptdel',
          PageIndex: 0,  // 0 代表全部
          PageSize: 0,   // 0 代表全部
          type: 'search',
          typecharone: type
        }
        setTimeout(() => {
          Api.getCloudConfig(param).then(res => {
            let data = res.data || []
            window.GLOB[sessionName] = data
  
            resolve(data)
          })
        }, delay)
      }
    })
  }
 
  open = (pictures, videos, colorlist) => {
    let filpictures = pictures
    let filvideos = videos
 
    let piclist = filpictures.filter((item, index) => index < this.state.pageSize)
    let vidlist = filvideos.filter((item, index) => index < this.state.pageSize)
 
    this.setState({
      visible: true,
      filpictures,
      filvideos,
      pictures,
      picIndex: 1,
      vidIndex: 1,
      imageKey: '',
      videoKey: '',
      piclist,
      vidlist,
      colorlist,
      videos
    })
  }
  
  handleSource = (item) => {
    this.setState({
      editvisible: true,
      card: item || null
    })
  }
 
  save = () => {
    const { card } = this.state
    this.editFormRef.handleConfirm().then(res => {
      res = {...card, ...res}
 
      if (!res.id) {
        res.id = Utils.getuuid()
      }
 
      Api.getCloudConfig({
        func: 's_url_db_adduptdel',
        id: res.id,
        PageIndex: 0, // 0 代表全部
        PageSize: 0,  // 0 代表全部
        remark: res.remark || '',
        linkurl: res.linkurl,
        typecharone: card.typecharone,
        type: card.id ? 'upt' : 'add'
      }).then(result => {
        if (result.status) {
          if (card.typecharone === 'image') {
            window.GLOB.app_pictures = result.data || []
            this.resetPicture(result.data || [])
          } else if (card.typecharone === 'video') {
            window.GLOB.app_videos = result.data || []
            this.resetVideo(result.data || [])
          } else if (card.typecharone === 'color') {
            window.GLOB.app_colors = result.data || []
            sessionStorage.setItem('app_colors', JSON.stringify(result.data || []))
            this.resetColor(result.data || [])
          }
          this.setState({editvisible: false})
        } else {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
        }
      })
    })
  }
 
  copySource = (item) => {
    if (item.linkurl) {
      let oInput = document.createElement('input')
      oInput.value = item.linkurl
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      document.body.removeChild(oInput)
 
      message.success('复制成功。')
    }
  }
 
  deleteSource = (item) => {
    const that = this
 
    confirm({
      title: '确定删除吗?',
      content: '',
      onOk() {
        return new Promise((resolve) => {
          Api.getCloudConfig({
            func: 's_url_db_adduptdel',
            id: item.id,
            PageIndex: 0, // 0 代表全部
            PageSize: 0,  // 0 代表全部
            remark: '',
            linkurl: '',
            typecharone: item.typecharone,
            type: 'del'
          }).then(res => {
            if (res.status) {
              if (item.typecharone === 'image') {
                window.GLOB.app_pictures = res.data || []
                that.resetPicture(res.data || [])
              } else if (item.typecharone === 'video') {
                window.GLOB.app_videos = res.data || []
                that.resetVideo(res.data || [])
              } else if (item.typecharone === 'color') {
                window.GLOB.app_colors = res.data || []
                sessionStorage.setItem('app_colors', JSON.stringify(res.data || []))
                that.resetColor(res.data || [])
              }
            } else {
              notification.warning({
                top: 92,
                message: res.message,
                duration: 5
              })
            }
            resolve()
          })
        })
      },
      onCancel() {}
    })
  }
 
  resetPicture = (data) => {
    const { imageKey, pageSize } = this.state
 
    let filpictures = data.filter(item => !imageKey || item.remark.indexOf(imageKey) > -1)
    let piclist = filpictures.filter((item, index) => index < pageSize)
 
    this.setState({picIndex: 1, filpictures, piclist, pictures: data})
  }
  
  resetVideo = (data) => {
    const { videoKey, pageSize } = this.state
 
    let filvideos = data.filter(item => !videoKey || item.remark.indexOf(videoKey) > -1)
    let vidlist = filvideos.filter((item, index) => index < pageSize)
 
    this.setState({vidIndex: 1, filvideos, vidlist, videos: data})
  }
  
  resetColor = (data) => {
    this.setState({colorlist: data})
  }
 
  filterPicture = () => {
    const { imageKey, pictures, pageSize } = this.state
 
    let filpictures = pictures.filter(item => !imageKey || item.remark.indexOf(imageKey) > -1)
    let piclist = filpictures.filter((item, index) => index < pageSize)
 
    this.setState({picIndex: 1, filpictures, piclist})
  }
  
  filterVideo = () => {
    const { videoKey, videos, pageSize } = this.state
 
    let filvideos = videos.filter(item => !videoKey || item.remark.indexOf(videoKey) > -1)
    let vidlist = filvideos.filter((item, index) => index < pageSize)
 
    this.setState({vidIndex: 1, filvideos, vidlist})
  }
 
  changePicSize = (page) => {
    const { filpictures, pageSize } = this.state
    let piclist = filpictures.filter((item, index) => index < pageSize * page && index >= pageSize * (page - 1))
 
    this.setState({picIndex: page, piclist})
  }
 
  changeVidSize = (page) => {
    const { filvideos, pageSize } = this.state
    let vidlist = filvideos.filter((item, index) => index < pageSize * page && index >= pageSize * (page - 1))
    
    this.setState({vidIndex: page, vidlist})
  }
  
  render() {
    const { visible, editvisible, card, filpictures, filvideos, piclist, vidlist, imageKey, videoKey, pageSize, picIndex, vidIndex, colorlist, iconlist } = this.state
 
    return (
      <>
        <Button className="mk-border-purple" onClick={this.trigger}><PictureOutlined /> 资源管理</Button>
        <Modal
          wrapClassName="mk-pop-modal picture-control-model"
          visible={visible}
          width={1200}
          maskClosable={false}
          onCancel={() => {this.setState({visible: false})}}
          footer={[
            <Button key="colse" onClick={() => {this.setState({visible: false})}}>
              关闭
            </Button>
          ]}
          destroyOnClose
        >
          <Tabs>
            <TabPane tab="图片管理" key="picture">
              <Row style={{marginBottom: '15px'}}>
                <Col span={8}>
                  <Search placeholder="" value={imageKey} onChange={(e) => this.setState({imageKey: e.target.value})} onSearch={this.filterPicture} enterButton />
                </Col>
                <Col span={16}>
                  <Button className="picture-plus mk-green" onClick={() => this.handleSource({typecharone: 'image'})}>
                    <PlusOutlined /> 添加
                  </Button>
                </Col>
              </Row>
              <Row gutter={16} style={{height: '340px'}}>
                {piclist.length > 0 && piclist.map(item => (
                  <Col span={4} key={item.id}>
                    <div className="image-video-box">
                      <div className="image-video-box-body">
                        <Image url={item.linkurl.replace(/@mywebsite@\//ig, window.GLOB.baseurl)} />
                      </div>
                      <div className="image-video-control">
                        <CopyOutlined onClick={() => this.copySource(item)}/>
                        <EditOutlined onClick={() => this.handleSource(item)}/>
                        <DeleteOutlined onClick={() => this.deleteSource(item)}/>
                      </div>
                    </div>
                    <p className="image-video-remark">{item.remark}</p>
                  </Col>
                ))}
                {!piclist.length ? <Empty description={null}/> : null}
              </Row>
              {filpictures.length > pageSize ? <Pagination size="small" current={picIndex} pageSize={pageSize} onChange={this.changePicSize} total={filpictures.length} /> : null}
            </TabPane>
            <TabPane tab="视频管理" key="video">
              <Row style={{marginBottom: '15px'}}>
                <Col span={8}>
                  <Search placeholder="" value={videoKey} onChange={e => this.setState({videoKey: e.target.value})} onSearch={this.filterVideo} enterButton />
                </Col>
                <Col span={16}>
                  <Button className="picture-plus mk-green" onClick={() => this.handleSource({typecharone: 'video'})}>
                    <PlusOutlined /> 添加
                  </Button>
                </Col>
              </Row>
              <Row gutter={16} style={{height: '340px'}}>
                {vidlist.length > 0 && vidlist.map(item => (
                  <Col span={4} key={item.id}>
                    <div className="image-video-box">
                      <div className="image-video-box-body">
                        <Video value={item.linkurl} />
                      </div>
                      <div className="image-video-control">
                        <CopyOutlined onClick={() => this.copySource(item)}/>
                        <EditOutlined onClick={() => this.handleSource(item)}/>
                        <DeleteOutlined onClick={() => this.deleteSource(item)}/>
                      </div>
                    </div>
                    <p className="image-video-remark">{item.remark}</p>
                  </Col>
                ))}
                {!vidlist.length ? <Empty description={null}/> : null}
              </Row>
              {filvideos.length > pageSize ? <Pagination size="small" current={vidIndex} pageSize={pageSize} onChange={this.changeVidSize} total={filvideos.length} /> : null}
            </TabPane>
            <TabPane tab="颜色管理" key="color">
              <Row style={{marginBottom: '15px'}}>
                <Col span={24}>
                  可添加应用中常用的颜色,可以是英文代码、HEX格式、RGB格式,最多可添加25种。
                  {colorlist.length < 25 ? <Button className="picture-plus mk-green" onClick={() => this.handleSource({typecharone: 'color'})}>
                    <PlusOutlined /> 添加
                  </Button> : null}
                </Col>
              </Row>
              <Row gutter={16} style={{height: '340px'}}>
                {colorlist.length > 0 && colorlist.map(item => (
                  <Col span={4} key={item.id}>
                    <div className="image-video-box">
                      <div className="image-video-box-body" style={{background: item.linkurl}}>
                      </div>
                      <div className="image-video-control">
                        <CopyOutlined onClick={() => this.copySource(item)}/>
                        <DeleteOutlined onClick={() => this.deleteSource(item)}/>
                      </div>
                    </div>
                    <p className="image-video-remark">{item.remark}</p>
                  </Col>
                ))}
                {!colorlist.length ? <Empty description={null}/> : null}
              </Row>
            </TabPane>
            <TabPane tab="图标库" key="icon">
              <Row gutter={16}>
                {iconlist.map(item => (
                  <Col className="icon-wrap" span={4} key={item}>
                    <MkIcon type={item} />
                    <Paragraph copyable={{ text: item }}>{item}</Paragraph>
                  </Col>
                ))}
              </Row>
            </TabPane>
          </Tabs>
        </Modal>
        <Modal
          title={card ? '编辑' : '新建'}
          wrapClassName="picture-edit-model"
          visible={editvisible}
          width={600}
          maskClosable={false}
          onOk={this.save}
          onCancel={() => {this.setState({editvisible: false})}}
          destroyOnClose
        >
          <EditForm card={card} wrappedComponentRef={(inst) => this.editFormRef = inst} inputSubmit={this.save}/>
        </Modal>
      </>
    )
  }
}
 
export default SourceController