beer-assembly-biz 1.1.1-alpha.12 → 1.1.1-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
package/MediaModals.js ADDED
@@ -0,0 +1,229 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { css } from '@emotion/css';
3
+ import { Breadcrumb, Dropdown, Input, Modal, Space, Typography } from 'antd';
4
+ import { CopyOutlined, DeleteOutlined, ExclamationCircleFilled, HighlightOutlined, RightCircleOutlined, ScissorOutlined } from '@ant-design/icons';
5
+ import DirectorySelect from 'beer-assembly/DirectorySelect';
6
+ import IconDirectory from './icon/directory.svg';
7
+ class MediaModals {
8
+ static useMedia(request) {
9
+ const [isOpenModal, setIsOpenModal] = useState(true);
10
+ const [isOpenMoveModal, setIsOpenMoveModal] = useState(false);
11
+ const [isOpenRenameModal, setIsOpenRenameModal] = useState(false);
12
+ const [isOpenConfirmModal, setIsOpenConfirmModal] = useState(false);
13
+ const [path, setPath] = useState([]);
14
+ const [dataList, setDataList] = useState([]);
15
+ const [selectId, setSelectId] = useState('');
16
+ const [selectName, setSelectName] = useState('');
17
+ const callbackRef = useRef(undefined);
18
+ const onOpenDirectory = async (id, name) => {
19
+ const paths = [...getPaths(), {
20
+ id,
21
+ name
22
+ }];
23
+ setPaths(paths);
24
+ };
25
+ const onBackDirectory = async (id) => {
26
+ const paths = getPaths();
27
+ const index = paths.findIndex(it => it.id === id);
28
+ if (index < 0) {
29
+ return;
30
+ }
31
+ paths.splice(index);
32
+ setPaths(paths);
33
+ };
34
+ const onSelectItem = async (id) => {
35
+ callbackRef?.current?.([id]);
36
+ };
37
+ const onRename = async (id, name) => {
38
+ setIsOpenRenameModal(true);
39
+ setSelectId(id);
40
+ setSelectName(name);
41
+ };
42
+ const onConfirmRename = async () => {
43
+ return request?.rename(selectId, selectName);
44
+ };
45
+ const onCopy = async (id) => {
46
+ return request?.copy(id);
47
+ };
48
+ const onMove = async (id) => {
49
+ setIsOpenMoveModal(true);
50
+ setSelectId(id);
51
+ };
52
+ const onConfirmMove = async (targetId) => {
53
+ request?.move(selectId, targetId);
54
+ };
55
+ const onRemove = async (id) => {
56
+ setIsOpenConfirmModal(true);
57
+ setSelectId(id);
58
+ };
59
+ const onConfirmRemove = async () => {
60
+ return request?.remove(selectId);
61
+ };
62
+ const setPaths = (items) => {
63
+ setPath(items);
64
+ sessionStorage.setItem('MEDIA_MODALS_PATHS', JSON.stringify(items));
65
+ };
66
+ const getPaths = () => {
67
+ const paths = JSON.parse(sessionStorage.getItem('MEDIA_MODALS_PATHS') || '[]');
68
+ if (paths.length <= 0) {
69
+ paths.push({
70
+ id: '0',
71
+ name: '根目录'
72
+ });
73
+ }
74
+ return paths;
75
+ };
76
+ const Item = (props) => {
77
+ const element = React.createElement("div", { style: {
78
+ padding: '8px 12px',
79
+ backgroundColor: props?.active ? '#e6f1ff' : undefined,
80
+ display: 'block',
81
+ margin: '0 auto',
82
+ cursor: 'pointer',
83
+ userSelect: 'none',
84
+ position: 'relative',
85
+ ...props.style
86
+ }, className: css `
87
+ border: ${props?.active ? '1px solid #cddef5' : '1px solid #fff'};
88
+
89
+ &:hover {
90
+ background-color: #eef1f5;
91
+ border: 1px solid ${props.active ? '#cddef5' : '#e6e6e6'};
92
+ }
93
+ `, onDoubleClick: () => (props.type === 'DIRECTORY' ? onOpenDirectory(props.id, props.name) : onSelectItem(props.id)) },
94
+ React.createElement("img", { src: props?.type === 'DIRECTORY' ? IconDirectory : props?.src, alt: "", style: {
95
+ width: 56,
96
+ height: 56,
97
+ margin: 'auto',
98
+ display: 'block',
99
+ overflow: 'hidden',
100
+ objectFit: props?.type === 'DIRECTORY' ? undefined : 'cover'
101
+ } }),
102
+ props?.rename ? React.createElement("input", { style: {
103
+ boxSizing: 'border-box',
104
+ width: 70,
105
+ fontSize: 12,
106
+ display: 'block',
107
+ outline: '1px solid #59ABFE',
108
+ border: '1px solid #59ABFE',
109
+ padding: '2px 3px',
110
+ borderRadius: 2,
111
+ marginTop: props?.type === 'DIRECTORY' ? undefined : 2
112
+ } }) : React.createElement(Typography.Text, { style: {
113
+ width: 70,
114
+ fontSize: 11,
115
+ display: 'block',
116
+ textAlign: 'center',
117
+ color: '#323232',
118
+ marginTop: props?.type === 'DIRECTORY' ? undefined : 1
119
+ }, ellipsis: true }, props?.name || '?'));
120
+ const menusItems = [
121
+ {
122
+ label: React.createElement(Space, { style: { width: 100 }, size: 5, onClick: () => onOpenDirectory(props.id, props.name) },
123
+ React.createElement(RightCircleOutlined, null),
124
+ "\u6253\u5F00\u76EE\u5F55"),
125
+ key: '0'
126
+ },
127
+ {
128
+ type: 'divider'
129
+ },
130
+ {
131
+ label: React.createElement(Space, { style: { width: 100 }, size: 5, onClick: () => onRename(props.id, props.name) },
132
+ React.createElement(HighlightOutlined, null),
133
+ "\u91CD\u547D\u540D"),
134
+ key: '1'
135
+ },
136
+ {
137
+ label: React.createElement(Space, { style: { width: 100 }, size: 5, onClick: () => onCopy(props.id) },
138
+ React.createElement(CopyOutlined, null),
139
+ "\u590D\u5236\u76EE\u5F55"),
140
+ key: '2'
141
+ },
142
+ {
143
+ label: React.createElement(Space, { style: { width: 100 }, size: 5, onClick: () => onMove(props.id) },
144
+ React.createElement(ScissorOutlined, null),
145
+ "\u79FB\u52A8\u76EE\u5F55"),
146
+ key: '3'
147
+ },
148
+ {
149
+ type: 'divider'
150
+ },
151
+ {
152
+ label: React.createElement(Space, { style: { width: 100 }, size: 5, onClick: () => onRemove(props.id) },
153
+ React.createElement(DeleteOutlined, null),
154
+ "\u5220\u9664\u76EE\u5F55"),
155
+ key: '4',
156
+ danger: true
157
+ }
158
+ ];
159
+ return props.active ? React.createElement(Dropdown, { menu: {
160
+ items: menusItems
161
+ }, trigger: ['contextMenu'] }, element) : element;
162
+ };
163
+ const handler = (callback) => {
164
+ setPath(getPaths());
165
+ setIsOpenModal(true);
166
+ if (callbackRef !== undefined) {
167
+ callbackRef.current = callback;
168
+ }
169
+ };
170
+ useEffect(() => {
171
+ if ((path || []).length <= 0) {
172
+ return;
173
+ }
174
+ const item = path[path.length - 1];
175
+ const chunkArray = (array, size) => {
176
+ const result = [];
177
+ for (let i = 0; i < array.length; i += size) {
178
+ result.push(array.slice(i, i + size));
179
+ }
180
+ return result;
181
+ };
182
+ request?.requestList?.(item.id)
183
+ .then(result => {
184
+ setDataList(chunkArray(result || [], 5));
185
+ });
186
+ }, path);
187
+ return [handler, React.createElement(React.Fragment, null,
188
+ React.createElement(Modal, { width: 565, footer: null, styles: {
189
+ content: { padding: 0 }
190
+ }, open: isOpenModal, title: React.createElement("div", { style: {
191
+ padding: '12px 0 8px 0',
192
+ borderBottom: '1px solid #ddd'
193
+ } },
194
+ React.createElement("img", { style: {
195
+ marginInlineStart: 20,
196
+ display: 'block',
197
+ width: '140px',
198
+ height: '30px',
199
+ backgroundColor: '#eee'
200
+ }, alt: "" })) },
201
+ React.createElement("div", { style: {
202
+ marginBottom: 6,
203
+ padding: '0 20px'
204
+ } },
205
+ React.createElement(Breadcrumb, { items: path?.map((it, index) => {
206
+ return { title: index + 1 === path.length ? it.name : React.createElement("a", { onClick: () => onBackDirectory(it.id) }, it.name) };
207
+ }) })),
208
+ React.createElement("div", { style: {
209
+ padding: '6px 0 24px 0',
210
+ height: 333,
211
+ maxHeight: 333,
212
+ overflowY: 'auto',
213
+ overflowX: 'hidden'
214
+ } }, dataList?.map((group, index) => (React.createElement("div", { key: index, style: {
215
+ padding: '0 20px 10px 20px',
216
+ display: 'flex'
217
+ } }, group?.map((item) => (React.createElement(Item, { id: item.id, key: item.id, style: { marginRight: 10 }, type: item.type, src: item.url, name: item.name })))))))),
218
+ React.createElement(Modal, { title: "\u91CD\u547D\u540D", width: 340, open: isOpenRenameModal, onOk: () => onConfirmRename(), onCancel: () => setIsOpenRenameModal(false), okText: "\u786E\u5B9A", cancelText: "\u53D6\u6D88" },
219
+ React.createElement(Input, null)),
220
+ React.createElement(Modal, { title: React.createElement(React.Fragment, null,
221
+ React.createElement(ExclamationCircleFilled, { style: {
222
+ marginRight: 6,
223
+ fontSize: 16,
224
+ color: '#faad14'
225
+ } }),
226
+ "\u662F\u5426\u786E\u8BA4\u5220\u9664\u76EE\u5F55?"), width: 400, open: isOpenConfirmModal, onOk: () => onConfirmRemove(), onCancel: () => setIsOpenConfirmModal(false), okText: "\u786E\u5B9A", cancelText: "\u53D6\u6D88" }, "\u5220\u9664\u64CD\u4F5C\u4E0D\u80FD\u56DE\u590D\uFF0C\u786E\u5B9A\u8981\u5220\u9664\u9009\u4E2D\u7684\u6587\u4EF6\u6216\u6587\u4EF6\u5939\u5417\uFF1F"),
227
+ React.createElement(DirectorySelect, { open: isOpenMoveModal, onOk: (value) => onConfirmMove(value) }))];
228
+ }
229
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "beer-assembly-biz",
3
3
  "private": false,
4
- "version": "1.1.1-alpha.12",
4
+ "version": "1.1.1-alpha.13",
5
5
  "scripts": {
6
6
  "pub-w": "tsc && copy package.json .\\dist\\package.json && npm publish ./dist",
7
7
  "pub-m": "tsc && cp -a src/icon ./dist && cp -a src/fonts ./dist && cp -a src/images ./dist && cp package.json ./dist/package.json && npm publish ./dist"