@vyr/design 0.0.1
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.
- package/package.json +16 -0
- package/src/components/Button.vue +64 -0
- package/src/components/Card.vue +203 -0
- package/src/components/Cascader.vue +171 -0
- package/src/components/Checked.vue +124 -0
- package/src/components/CheckedGroup.vue +51 -0
- package/src/components/Col.vue +52 -0
- package/src/components/ColorPicker.vue +331 -0
- package/src/components/Confirm.vue +86 -0
- package/src/components/Dialog.vue +220 -0
- package/src/components/Divider.vue +40 -0
- package/src/components/Draggable.vue +50 -0
- package/src/components/Dropdown.vue +175 -0
- package/src/components/DynamicDialog.vue +113 -0
- package/src/components/DynamicLayouter.vue +235 -0
- package/src/components/Form.vue +88 -0
- package/src/components/Input.vue +254 -0
- package/src/components/InputNumber.vue +96 -0
- package/src/components/Label.vue +116 -0
- package/src/components/Loading.vue +196 -0
- package/src/components/Mask.vue +47 -0
- package/src/components/Notify.vue +130 -0
- package/src/components/Option.vue +159 -0
- package/src/components/Options.vue +202 -0
- package/src/components/Popover.vue +271 -0
- package/src/components/Provider.vue +12 -0
- package/src/components/RightMenu.vue +127 -0
- package/src/components/Row.vue +50 -0
- package/src/components/Scroll.vue +99 -0
- package/src/components/Select.vue +223 -0
- package/src/components/Slot.vue +23 -0
- package/src/components/SubTree.vue +262 -0
- package/src/components/Tree.vue +129 -0
- package/src/components/common/DraggableController.ts +113 -0
- package/src/components/common/ResizeListener.ts +49 -0
- package/src/components/composables/useDefaultProps.ts +179 -0
- package/src/components/composables/useDraggable.ts +65 -0
- package/src/components/composables/useGetter.ts +15 -0
- package/src/components/composables/useMarginStyle.ts +45 -0
- package/src/components/composables/usePopover.ts +33 -0
- package/src/components/composables/useProvider.ts +186 -0
- package/src/components/composables/useScroll.ts +46 -0
- package/src/components/composables/useSearch.ts +97 -0
- package/src/components/composables/useTimer.ts +5 -0
- package/src/components/index.ts +1 -0
- package/src/components/singleton/confirm.ts +25 -0
- package/src/components/singleton/dialog.ts +25 -0
- package/src/components/singleton/index.ts +5 -0
- package/src/components/singleton/loading.ts +36 -0
- package/src/components/singleton/notify.ts +36 -0
- package/src/components/types/index.ts +82 -0
- package/src/components/utils/Cascader.ts +52 -0
- package/src/components/utils/Confirm.ts +41 -0
- package/src/components/utils/Dialog.ts +38 -0
- package/src/components/utils/DynamicDialog.ts +41 -0
- package/src/components/utils/DynamicLayouter.ts +5 -0
- package/src/components/utils/FloatLayer.ts +40 -0
- package/src/components/utils/InputNumber.ts +3 -0
- package/src/components/utils/Notify.ts +25 -0
- package/src/components/utils/Popover.ts +58 -0
- package/src/components/utils/RightMenu.ts +21 -0
- package/src/components/utils/Scroll.ts +4 -0
- package/src/components/utils/Slot.ts +73 -0
- package/src/components/utils/index.ts +12 -0
- package/src/font/demo.css +539 -0
- package/src/font/demo_index.html +1292 -0
- package/src/font/iconfont.css +207 -0
- package/src/font/iconfont.js +1 -0
- package/src/font/iconfont.json +345 -0
- package/src/font/iconfont.ttf +0 -0
- package/src/font/iconfont.woff +0 -0
- package/src/font/iconfont.woff2 +0 -0
- package/src/index.ts +68 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +38 -0
- package/src/locale/index.ts +2 -0
- package/src/theme/global.less +91 -0
- package/src/theme/index.ts +155 -0
- package/src/tool/ArrayUtils.ts +38 -0
- package/src/tool/Color.ts +7 -0
- package/src/tool/Draggable.ts +36 -0
- package/src/tool/Listener.ts +59 -0
- package/src/tool/index.ts +4 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ref, Ref } from "vue"
|
|
2
|
+
|
|
3
|
+
const useScroll = (computeTop: () => void, wrapper: Ref<HTMLElement>) => {
|
|
4
|
+
const scroll = {
|
|
5
|
+
tick: 0,
|
|
6
|
+
count: 0,
|
|
7
|
+
stopWheel: false,
|
|
8
|
+
}
|
|
9
|
+
const opacity = ref(0)
|
|
10
|
+
|
|
11
|
+
const loop = () => {
|
|
12
|
+
scroll.tick = requestAnimationFrame(loop)
|
|
13
|
+
computeTop()
|
|
14
|
+
}
|
|
15
|
+
const stop = () => {
|
|
16
|
+
cancelAnimationFrame(scroll.tick)
|
|
17
|
+
scroll.tick = 0
|
|
18
|
+
}
|
|
19
|
+
const delay = () => {
|
|
20
|
+
scroll.count--
|
|
21
|
+
if (scroll.count > 0) return
|
|
22
|
+
stop()
|
|
23
|
+
}
|
|
24
|
+
const layout = (e: WheelEvent) => {
|
|
25
|
+
if (scroll.stopWheel === true) e.preventDefault()
|
|
26
|
+
if (scroll.tick === 0) loop()
|
|
27
|
+
scroll.count++
|
|
28
|
+
setTimeout(delay, 300);
|
|
29
|
+
}
|
|
30
|
+
const move = () => {
|
|
31
|
+
opacity.value = 0.75
|
|
32
|
+
}
|
|
33
|
+
const leave = () => {
|
|
34
|
+
stop()
|
|
35
|
+
opacity.value = 0
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
opacity,
|
|
40
|
+
layout,
|
|
41
|
+
move,
|
|
42
|
+
leave,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { useScroll }
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ref } from "vue"
|
|
2
|
+
import { Theme } from "../../theme"
|
|
3
|
+
import { DataGetter, DefineToDefaultProps, Options } from "../types"
|
|
4
|
+
import { cascaderProviderDefault } from "./useProvider"
|
|
5
|
+
import { useTimer } from "./useTimer"
|
|
6
|
+
|
|
7
|
+
type SearchFunctionProp = (value: string, options: Options) => Options
|
|
8
|
+
interface SearchDefaultProps {
|
|
9
|
+
/**开启选项的搜索功能
|
|
10
|
+
*
|
|
11
|
+
* false:关闭搜索功能
|
|
12
|
+
*
|
|
13
|
+
* true:使用默认的搜索方法进行搜索
|
|
14
|
+
*
|
|
15
|
+
* function:使用的自定义的方法进行搜索
|
|
16
|
+
*/
|
|
17
|
+
searchable: SearchFunctionProp | boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const searchDefaultProps: DefineToDefaultProps<SearchDefaultProps, boolean> = { searchable: { default: false } }
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const useSearch = (props: { searchable: SearchFunctionProp | boolean, data: Options }, cascader: typeof cascaderProviderDefault, getter: DataGetter) => {
|
|
24
|
+
const searchState = ref({
|
|
25
|
+
/**过滤输入框的当前状态
|
|
26
|
+
*
|
|
27
|
+
* 0: 未进行过滤或本次过滤操作已结束
|
|
28
|
+
*
|
|
29
|
+
* 1: 点击输入框,开启过滤功能
|
|
30
|
+
*
|
|
31
|
+
* 2: 正在输入过滤字符
|
|
32
|
+
*
|
|
33
|
+
* 3: 已停止输入,需要显示匹配的过滤项
|
|
34
|
+
*
|
|
35
|
+
* 4: 输入框失去焦点(选择了过滤项或取消本次选择)
|
|
36
|
+
*/
|
|
37
|
+
status: 0,
|
|
38
|
+
timeout: 0,
|
|
39
|
+
forcedPrompt: false,
|
|
40
|
+
count: 0,
|
|
41
|
+
content: '',
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const startSearch = () => {
|
|
45
|
+
clearTimeout(searchState.value.timeout)
|
|
46
|
+
searchState.value.status = 1
|
|
47
|
+
cascader.value.searchOptions = []
|
|
48
|
+
}
|
|
49
|
+
const delaySearch = () => {
|
|
50
|
+
searchState.value.count--
|
|
51
|
+
if (searchState.value.count > 0 || props.searchable === false) return
|
|
52
|
+
|
|
53
|
+
searchState.value.forcedPrompt = false
|
|
54
|
+
if (searchState.value.content === '') {
|
|
55
|
+
searchState.value.status = 1
|
|
56
|
+
cascader.value.searchOptions = []
|
|
57
|
+
} else {
|
|
58
|
+
searchState.value.status = 3
|
|
59
|
+
const options = props.searchable === true ? cascader.value.getSearchOptions(searchState.value.content, props.data, getter) : props.searchable(searchState.value.content, props.data)
|
|
60
|
+
|
|
61
|
+
if (options.length === 0) {
|
|
62
|
+
searchState.value.forcedPrompt = true
|
|
63
|
+
options.push({ label: '', value: '', disabled: true })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
cascader.value.searchOptions = options
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const updateSearch = (value: string) => {
|
|
70
|
+
searchState.value.count++
|
|
71
|
+
searchState.value.status = 2
|
|
72
|
+
searchState.value.content = value
|
|
73
|
+
searchState.value.timeout = useTimer(delaySearch, 200)
|
|
74
|
+
|
|
75
|
+
setTimeout
|
|
76
|
+
}
|
|
77
|
+
const delayClear = () => {
|
|
78
|
+
searchState.value.status = 0
|
|
79
|
+
searchState.value.content = ''
|
|
80
|
+
searchState.value.forcedPrompt = false
|
|
81
|
+
cascader.value.searchOptions = []
|
|
82
|
+
}
|
|
83
|
+
const clearSearch = () => {
|
|
84
|
+
clearTimeout(searchState.value.timeout)
|
|
85
|
+
searchState.value.status = 4
|
|
86
|
+
searchState.value.timeout = useTimer(delayClear, Theme.config.animationTime.value)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
searchState,
|
|
91
|
+
startSearch,
|
|
92
|
+
updateSearch,
|
|
93
|
+
clearSearch,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { searchDefaultProps, useSearch }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { Confirm, confirmKey, getConfirmState } from '../utils'
|
|
3
|
+
import ConfirmVue from '../Confirm.vue'
|
|
4
|
+
|
|
5
|
+
const confirm = (config: Partial<Confirm> = {}) => {
|
|
6
|
+
const app = createApp(ConfirmVue)
|
|
7
|
+
|
|
8
|
+
const promise = new Promise<Confirm>((resolve) => {
|
|
9
|
+
const state = getConfirmState(config, (success) => {
|
|
10
|
+
state.value.visible = false
|
|
11
|
+
app.unmount()
|
|
12
|
+
config.value = state.value.value
|
|
13
|
+
config.success = success
|
|
14
|
+
resolve(config as Confirm)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
app.provide(confirmKey, state)
|
|
18
|
+
app.mount(document.createElement('div'))
|
|
19
|
+
state.value.visible = true
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return promise
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { confirm }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { Dialog, dialogKey, getDialogState } from '../utils'
|
|
3
|
+
import DynamicDialog from '../DynamicDialog.vue'
|
|
4
|
+
|
|
5
|
+
const dialog = (config: Partial<Dialog> = {}) => {
|
|
6
|
+
const app = createApp(DynamicDialog)
|
|
7
|
+
|
|
8
|
+
const promise = new Promise<Dialog>((resolve) => {
|
|
9
|
+
const state = getDialogState(config, (success) => {
|
|
10
|
+
state.value.visible = false
|
|
11
|
+
app.unmount()
|
|
12
|
+
config.value = state.value.value
|
|
13
|
+
config.success = success
|
|
14
|
+
resolve(config as Dialog)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
app.provide(dialogKey, state)
|
|
18
|
+
app.mount(document.createElement('div'))
|
|
19
|
+
state.value.visible = true
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return promise
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { dialog }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { LoadingVue } from '../types'
|
|
3
|
+
import SnowLoading from '../Loading.vue'
|
|
4
|
+
|
|
5
|
+
class Loading {
|
|
6
|
+
static show() { }
|
|
7
|
+
static close() { }
|
|
8
|
+
|
|
9
|
+
private count = 0
|
|
10
|
+
private vm
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
const app = createApp(SnowLoading)
|
|
14
|
+
this.vm = app.mount(document.createElement('div')) as unknown as LoadingVue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
show() {
|
|
18
|
+
if (this.count === 0) {
|
|
19
|
+
this.vm.setVisible(true)
|
|
20
|
+
Loading.show()
|
|
21
|
+
}
|
|
22
|
+
this.count++
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
close() {
|
|
26
|
+
this.count--
|
|
27
|
+
if (this.count > 0) return
|
|
28
|
+
this.vm.setVisible(false)
|
|
29
|
+
this.count = 0
|
|
30
|
+
Loading.close()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const loading = new Loading()
|
|
35
|
+
|
|
36
|
+
export { Loading, loading }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { NotifyVue } from '../types'
|
|
3
|
+
import { NotifySetting } from '../utils'
|
|
4
|
+
import { language } from "../../locale"
|
|
5
|
+
import SnowNotify from '../Notify.vue'
|
|
6
|
+
|
|
7
|
+
class Notify {
|
|
8
|
+
|
|
9
|
+
send(message: string): void
|
|
10
|
+
send(message: string, type: NotifySetting['type']): void
|
|
11
|
+
send(message: string, duration: number): void
|
|
12
|
+
send(message: string, type: NotifySetting['type'], duration: number): void
|
|
13
|
+
send(message: string, td?: NotifySetting['type'] | number, duration?: number) {
|
|
14
|
+
const notify = typeof message === 'string' ? { message } : message
|
|
15
|
+
if (notify.message === '') return console.warn(language.get('notify.send.notMessage'))
|
|
16
|
+
|
|
17
|
+
const app = createApp(SnowNotify)
|
|
18
|
+
const vm = app.mount(document.createElement('div')) as unknown as NotifyVue
|
|
19
|
+
|
|
20
|
+
let type
|
|
21
|
+
typeof td === 'string' ? type = td : duration = td
|
|
22
|
+
|
|
23
|
+
const close = () => app.unmount()
|
|
24
|
+
const setting = new NotifySetting(message, type, duration, close)
|
|
25
|
+
|
|
26
|
+
vm.show(setting)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setOffset(offset: number) {
|
|
30
|
+
NotifySetting.offset = offset
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const notify = new Notify()
|
|
35
|
+
|
|
36
|
+
export { notify }
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { NotifySetting, RightMenuSetting } from "../utils"
|
|
2
|
+
|
|
3
|
+
type GetPropValue<V> = V | V[]
|
|
4
|
+
type GetPropsValue<T, V> = T extends string | number | boolean | symbol ? T | V : (() => T) | V
|
|
5
|
+
type DefineToDefaultProps<P extends { [k: string]: any } = {}, V = null> = { [K in keyof P]: { default: GetPropsValue<P[K], V> } }
|
|
6
|
+
type ToPartialObject<P extends { [k: string]: any } = {}> = { [K in keyof P]: Partial<P[K]> }
|
|
7
|
+
|
|
8
|
+
interface DataGetter<T extends any = any> {
|
|
9
|
+
label(item: T): string
|
|
10
|
+
value(item: T): string
|
|
11
|
+
arrow(item: T): boolean
|
|
12
|
+
disabled(item: T): boolean
|
|
13
|
+
children(item: T): T[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Option {
|
|
17
|
+
[k: string]: any
|
|
18
|
+
label?: string
|
|
19
|
+
value?: any
|
|
20
|
+
arrow?: boolean
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
children?: Option[]
|
|
23
|
+
}
|
|
24
|
+
interface Options extends Array<Option> { }
|
|
25
|
+
|
|
26
|
+
interface SelectPopoverLayout {
|
|
27
|
+
position: string[]
|
|
28
|
+
width: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface CascaderOption extends Option {
|
|
32
|
+
children?: CascaderOption[]
|
|
33
|
+
}
|
|
34
|
+
interface CascaderOptions extends Array<CascaderOption> { }
|
|
35
|
+
|
|
36
|
+
interface ValidateCollection { [k: string]: string }
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
interface TreeOption extends Option {
|
|
40
|
+
[k: string]: any
|
|
41
|
+
children?: TreeOption[]
|
|
42
|
+
}
|
|
43
|
+
interface TreeOptions extends Array<TreeOption> { }
|
|
44
|
+
interface SubTreeSlots { default?: (props: { item: TreeOption, active: boolean }) => any }
|
|
45
|
+
|
|
46
|
+
interface DraggableVue {
|
|
47
|
+
update(x: number, y: number): void
|
|
48
|
+
show(name: string): void
|
|
49
|
+
hide(): void
|
|
50
|
+
}
|
|
51
|
+
interface LoadingVue {
|
|
52
|
+
setVisible(v: boolean): void
|
|
53
|
+
}
|
|
54
|
+
interface RightMenuVue {
|
|
55
|
+
show(setting: RightMenuSetting): void
|
|
56
|
+
close(): void
|
|
57
|
+
}
|
|
58
|
+
interface NotifyVue {
|
|
59
|
+
show(setting: NotifySetting): void
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
GetPropValue,
|
|
65
|
+
GetPropsValue,
|
|
66
|
+
DefineToDefaultProps,
|
|
67
|
+
ToPartialObject,
|
|
68
|
+
DataGetter,
|
|
69
|
+
Option,
|
|
70
|
+
Options,
|
|
71
|
+
SelectPopoverLayout,
|
|
72
|
+
CascaderOption,
|
|
73
|
+
CascaderOptions,
|
|
74
|
+
ValidateCollection,
|
|
75
|
+
TreeOption,
|
|
76
|
+
TreeOptions,
|
|
77
|
+
SubTreeSlots,
|
|
78
|
+
DraggableVue,
|
|
79
|
+
LoadingVue,
|
|
80
|
+
RightMenuVue,
|
|
81
|
+
NotifyVue,
|
|
82
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CascaderOption, CascaderOptions, Options, DataGetter } from '../types'
|
|
2
|
+
|
|
3
|
+
const getInputValue = (v: string, options: Options, getter: DataGetter): string => {
|
|
4
|
+
for (const option of options) {
|
|
5
|
+
if (getter.value(option) === v) return getter.label(option)
|
|
6
|
+
const children = getter.children(option)
|
|
7
|
+
if (children.length === 0) continue
|
|
8
|
+
const value = getInputValue(v, children, getter)
|
|
9
|
+
if (value) return getter.label(option) + ' / ' + value
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return ''
|
|
13
|
+
}
|
|
14
|
+
const getSelectOptions = (tree: CascaderOptions, value: CascaderOption['value'], getter: DataGetter, checked: CascaderOptions = []) => {
|
|
15
|
+
|
|
16
|
+
for (const item of tree) {
|
|
17
|
+
if (getter.value(item) === value) {
|
|
18
|
+
checked.push(item)
|
|
19
|
+
return checked
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const children = getter.children(item)
|
|
23
|
+
if (children.length > 0) getSelectOptions(children, value, getter, checked)
|
|
24
|
+
|
|
25
|
+
if (checked.length > 0) {
|
|
26
|
+
checked.push(item)
|
|
27
|
+
return checked
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return checked
|
|
32
|
+
}
|
|
33
|
+
const getSearchOptions = (value: string, options: CascaderOptions, getter: DataGetter) => {
|
|
34
|
+
const filterOptions: Options = []
|
|
35
|
+
for (const option of options) {
|
|
36
|
+
const children = getter.children(option)
|
|
37
|
+
if (children.length > 0) {
|
|
38
|
+
filterOptions.push(...getSearchOptions(value, children, getter))
|
|
39
|
+
} else {
|
|
40
|
+
if (getter.disabled(option) === true) continue
|
|
41
|
+
if (getter.label(option).indexOf(value) > -1) filterOptions.push(option)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return filterOptions
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
getInputValue,
|
|
50
|
+
getSelectOptions,
|
|
51
|
+
getSearchOptions,
|
|
52
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { inject, ref } from "vue"
|
|
2
|
+
import { language } from "../../locale"
|
|
3
|
+
import { Option } from ".."
|
|
4
|
+
|
|
5
|
+
interface ConfirmOptions extends Array<Option> { }
|
|
6
|
+
|
|
7
|
+
interface Confirm {
|
|
8
|
+
type: string
|
|
9
|
+
title: string
|
|
10
|
+
message: string
|
|
11
|
+
value: any
|
|
12
|
+
options: ConfirmOptions
|
|
13
|
+
mode: string
|
|
14
|
+
placeholder: string
|
|
15
|
+
success: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const confirmKey = Symbol('vyr-confirm')
|
|
19
|
+
|
|
20
|
+
const getConfirmState = (config: Partial<Confirm>, close = (state: boolean) => { }) => {
|
|
21
|
+
return ref({
|
|
22
|
+
visible: false,
|
|
23
|
+
title: config.title,
|
|
24
|
+
type: config.type,
|
|
25
|
+
options: config.options ?? [],
|
|
26
|
+
message: config.message,
|
|
27
|
+
mode: config.mode,
|
|
28
|
+
value: config.value,
|
|
29
|
+
placeholder: config.placeholder,
|
|
30
|
+
success: false,
|
|
31
|
+
close
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const useConfirmState = () => {
|
|
36
|
+
const confirm = inject(confirmKey, () => { throw language.get('confirm.state.notFound') }) as unknown as ReturnType<typeof getConfirmState>
|
|
37
|
+
|
|
38
|
+
return confirm
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { ConfirmOptions, Confirm, confirmKey, getConfirmState, useConfirmState }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const dialogPrivateWarp = document.body
|
|
2
|
+
const getDialogWrapRect = () => {
|
|
3
|
+
const rect = {
|
|
4
|
+
width: dialogPrivateWarp.clientWidth,
|
|
5
|
+
height: dialogPrivateWarp.clientHeight
|
|
6
|
+
}
|
|
7
|
+
return rect
|
|
8
|
+
}
|
|
9
|
+
const getDialogWrapHeight = (maxHeight: string) => {
|
|
10
|
+
|
|
11
|
+
let index = maxHeight.indexOf('%')
|
|
12
|
+
if (index > -1) {
|
|
13
|
+
const rect = getDialogWrapRect()
|
|
14
|
+
const radio = parseFloat(maxHeight.slice(0, index))
|
|
15
|
+
return Math.floor(rect.height * radio / 100)
|
|
16
|
+
}
|
|
17
|
+
let number = maxHeight
|
|
18
|
+
index = maxHeight.indexOf('px')
|
|
19
|
+
if (index > -1) {
|
|
20
|
+
number = maxHeight.slice(0, index)
|
|
21
|
+
}
|
|
22
|
+
const height = parseFloat(number)
|
|
23
|
+
|
|
24
|
+
return isNaN(height) ? 0 : height
|
|
25
|
+
}
|
|
26
|
+
const getDialogHeight = (dom: Element) => {
|
|
27
|
+
const height = getComputedStyle(dom).height
|
|
28
|
+
if (!height) return 0
|
|
29
|
+
const number = (parseInt(height.split('px')[0]))
|
|
30
|
+
return isNaN(number) ? 0 : number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
dialogPrivateWarp,
|
|
35
|
+
getDialogWrapRect,
|
|
36
|
+
getDialogWrapHeight,
|
|
37
|
+
getDialogHeight,
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { inject, ref } from "vue"
|
|
2
|
+
import { language } from "../../locale"
|
|
3
|
+
import { Option } from "../types"
|
|
4
|
+
|
|
5
|
+
interface DialogOptions extends Array<{
|
|
6
|
+
label: string
|
|
7
|
+
name: string
|
|
8
|
+
componentType: 'input' | 'number' | 'select' | 'cascader' | 'color' | 'image'
|
|
9
|
+
componentProps: { [k: string]: any }
|
|
10
|
+
componentData?: Option[] | ((result: { [k: string]: any }) => Option[])
|
|
11
|
+
}> { }
|
|
12
|
+
|
|
13
|
+
interface Dialog {
|
|
14
|
+
type: string
|
|
15
|
+
title: string
|
|
16
|
+
value: { [k: string]: any }
|
|
17
|
+
options: DialogOptions
|
|
18
|
+
success: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const dialogKey = Symbol('vyr-dialog')
|
|
22
|
+
|
|
23
|
+
const getDialogState = (config: Partial<Dialog>, close = (state: boolean) => { }) => {
|
|
24
|
+
return ref({
|
|
25
|
+
visible: false,
|
|
26
|
+
title: config.title,
|
|
27
|
+
type: config.type,
|
|
28
|
+
options: config.options ?? [],
|
|
29
|
+
value: config.value,
|
|
30
|
+
success: false,
|
|
31
|
+
close
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const useDialogState = () => {
|
|
36
|
+
const dialog = inject(dialogKey, () => { throw language.get('dialog.state.notFound') }) as unknown as ReturnType<typeof getDialogState>
|
|
37
|
+
|
|
38
|
+
return dialog
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { DialogOptions, Dialog, dialogKey, getDialogState, useDialogState }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { ArrayUtils } from "../../tool";
|
|
3
|
+
|
|
4
|
+
let floatId = 1
|
|
5
|
+
|
|
6
|
+
const floatLayer = ref({
|
|
7
|
+
queue: [] as number[],
|
|
8
|
+
active: -1,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const generateFloatLayer = () => {
|
|
12
|
+
return floatId++
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const addFloatLayer = (id: number) => {
|
|
16
|
+
ArrayUtils.insert(floatLayer.value.queue, id)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const removeFloatLayer = (id: number) => {
|
|
20
|
+
ArrayUtils.remove(floatLayer.value.queue, id)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const seActiveLayer = (id: number) => {
|
|
24
|
+
removeFloatLayer(id)
|
|
25
|
+
addFloatLayer(id)
|
|
26
|
+
floatLayer.value.active = id
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const isActiveLayer = (id: number) => {
|
|
30
|
+
return floatLayer.value.active === id
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const computedFloatLayer = (id: number, active = false) => {
|
|
34
|
+
const i = floatLayer.value.queue.indexOf(id)
|
|
35
|
+
if (i === -1) return i
|
|
36
|
+
const z = active ? floatLayer.value.queue.length : i
|
|
37
|
+
return z * 2 + 1000
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { floatLayer, generateFloatLayer, addFloatLayer, removeFloatLayer, seActiveLayer, isActiveLayer, computedFloatLayer }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Ref, ref } from "vue"
|
|
2
|
+
|
|
3
|
+
class NotifySetting {
|
|
4
|
+
static map = { success: 'success', warning: 'warning', danger: 'shanchu' }
|
|
5
|
+
static collection: Ref<NotifySetting[]> = ref([])
|
|
6
|
+
static offset = 0
|
|
7
|
+
|
|
8
|
+
readonly type
|
|
9
|
+
readonly message
|
|
10
|
+
readonly duration
|
|
11
|
+
readonly icon
|
|
12
|
+
readonly close
|
|
13
|
+
visible = false
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
constructor(message: string, type: 'success' | 'warning' | 'danger' = 'danger', duration = 3000, close = () => { }) {
|
|
17
|
+
this.type = type
|
|
18
|
+
this.message = message
|
|
19
|
+
this.duration = duration
|
|
20
|
+
this.icon = NotifySetting.map[type]
|
|
21
|
+
this.close = close
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { NotifySetting }
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
popperGenerator,
|
|
3
|
+
defaultModifiers,
|
|
4
|
+
OptionsGeneric,
|
|
5
|
+
} from '@popperjs/core/lib/popper-lite';
|
|
6
|
+
import flip from '@popperjs/core/lib/modifiers/flip';
|
|
7
|
+
import modifiers_hide from '@popperjs/core/lib/modifiers/hide';
|
|
8
|
+
import modifiers_offset from '@popperjs/core/lib/modifiers/offset';
|
|
9
|
+
import modifiers_arrow from '@popperjs/core/lib/modifiers/arrow';
|
|
10
|
+
import eventListeners from '@popperjs/core/lib/modifiers/eventListeners';
|
|
11
|
+
import preventOverflow from '@popperjs/core/lib/modifiers/preventOverflow';
|
|
12
|
+
|
|
13
|
+
const createPopper = popperGenerator({
|
|
14
|
+
defaultModifiers: [...defaultModifiers, modifiers_offset, modifiers_arrow, modifiers_hide, flip, preventOverflow, eventListeners],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const getArrow = (arrow: boolean, offset: number, enabled: boolean) => {
|
|
18
|
+
return { name: 'offset', options: { offset: [0, arrow ? offset : 0] }, enabled, }
|
|
19
|
+
}
|
|
20
|
+
const getOptions = (props: any, v = false): Pick<OptionsGeneric<any>, 'modifiers' | 'placement'> => {
|
|
21
|
+
const defaultMods = [
|
|
22
|
+
{ name: 'arrow', options: { padding: props.arrow ? 5 : 0 }, enabled: v, },
|
|
23
|
+
{ name: 'preventOverflow', options: { padding: 0 }, enabled: v, },
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
placement: props.placement,
|
|
28
|
+
modifiers: [
|
|
29
|
+
getArrow(props.arrow, props.offset, v),
|
|
30
|
+
...defaultMods,
|
|
31
|
+
{ name: 'eventListeners', enabled: v },
|
|
32
|
+
{ name: 'applyStyles', enabled: v }
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const isContains = (target: any | undefined, list: any[]) => {
|
|
37
|
+
if (target === undefined) return false
|
|
38
|
+
|
|
39
|
+
for (const item of list) {
|
|
40
|
+
if (item.contains(target)) return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const tooltip = {
|
|
47
|
+
wrapper: document.createElement('div'),
|
|
48
|
+
setup() {
|
|
49
|
+
this.wrapper.setAttribute('class', 'tooltip')
|
|
50
|
+
this.wrapper.setAttribute('id', 'tooltip')
|
|
51
|
+
this.wrapper.style.display = 'contents'
|
|
52
|
+
document.body.appendChild(this.wrapper)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
tooltip.setup()
|
|
56
|
+
|
|
57
|
+
export { createPopper, getOptions, isContains, tooltip }
|
|
58
|
+
|