command-center-v3-common 0.0.13 → 0.0.15

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.
@@ -1,71 +0,0 @@
1
- import WujieVue from 'wujie-vue3'
2
- import { logger } from '@/utils/logger'
3
-
4
- const { bus } = WujieVue
5
-
6
- export type EventCallback = (...args: Array<any>) => any
7
-
8
- export class EventBus {
9
- private bus: any
10
- private framework: string
11
-
12
- constructor(framework?: string) {
13
- this.framework = framework || 'wujie'
14
- this.bus = this.initializeBus()
15
- }
16
-
17
- private initializeBus(): any {
18
- switch (this.framework) {
19
- case 'wujie':
20
- return window.$wujie ? window.$wujie.bus : bus
21
- // 如果未来切换到其他微前端框架,可以在这里初始化相应的 bus
22
- case 'otherFramework':
23
- // return window.$otherFramework?.bus;
24
- break
25
- default:
26
- logger.warning('EventBus', 'init', '未检测到已识别的微前端框架')
27
- return null
28
- }
29
- }
30
-
31
- public on(event: string, callback: EventCallback): void {
32
- if (!this.bus)
33
- return logger.warning('EventBus', 'on', '没有可用于当前框架的总线')
34
-
35
- if (typeof callback !== 'function')
36
- return logger.error('EventBus', 'on', '回调必须是一个函数')
37
-
38
- this.bus.$on(event, callback)
39
- }
40
-
41
- public once(event: string, callback: EventCallback): void {
42
- if (!this.bus)
43
- return logger.warning('EventBus', 'once', '没有可用于当前框架的总线')
44
-
45
- if (typeof callback !== 'function')
46
- return logger.error('EventBus', 'once', '回调必须是一个函数')
47
-
48
- this.bus.$once(event, callback)
49
- }
50
-
51
- public emit(event: string, ...args: any[]): void {
52
- if (!this.bus)
53
- return logger.warning('EventBus', 'emit', '没有可用于当前框架的总线')
54
-
55
- this.bus.$emit(event, ...args)
56
- }
57
-
58
- public off(event: string, callback: EventCallback): void {
59
- if (!this.bus)
60
- return logger.warning('EventBus', 'off', '没有可用于当前框架的总线')
61
-
62
- this.bus.$off(event, callback)
63
- }
64
-
65
- public clear(): void {
66
- if (!this.bus)
67
- return logger.warning('EventBus', 'clear', '没有可用于当前框架的总线')
68
-
69
- this.bus.$clear()
70
- }
71
- }
@@ -1,36 +0,0 @@
1
- enum CacheType {
2
- Local,
3
- Session
4
- }
5
-
6
- class Cache {
7
- storage: Storage
8
-
9
- constructor(type: CacheType) {
10
- this.storage = type === CacheType.Local ? localStorage : sessionStorage
11
- }
12
-
13
- setCache(key: string, value: any) {
14
- if (value)
15
- this.storage.setItem(key, JSON.stringify(value))
16
- }
17
-
18
- getCache(key: string) {
19
- const value = this.storage.getItem(key)
20
- if (value)
21
- return JSON.parse(value)
22
- }
23
-
24
- removeCache(key: string) {
25
- this.storage.removeItem(key)
26
- }
27
-
28
- clear() {
29
- this.storage.clear()
30
- }
31
- }
32
-
33
- const localCache = new Cache(CacheType.Local)
34
- const sessionCache = new Cache(CacheType.Session)
35
-
36
- export { localCache, sessionCache }
@@ -1,102 +0,0 @@
1
- const toString = Object.prototype.toString
2
-
3
- export function is(val: unknown, type: string) {
4
- return toString.call(val) === `[object ${type}]`
5
- }
6
-
7
- export function isDef<T = unknown>(val?: T): val is T {
8
- return typeof val !== 'undefined'
9
- }
10
-
11
- export function isUnDef<T = unknown>(val?: T): val is T {
12
- return !isDef(val)
13
- }
14
-
15
- export function isObject(val: any): val is Record<any, any> {
16
- return val !== null && is(val, 'Object')
17
- }
18
-
19
- export function isEmpty<T = unknown>(val: T): val is T {
20
- if (isArray(val) || isString(val))
21
- return val.length === 0
22
-
23
- if (val instanceof Map || val instanceof Set)
24
- return val.size === 0
25
-
26
- if (isObject(val))
27
- return Object.keys(val).length === 0
28
-
29
- return false
30
- }
31
-
32
- export function isDate(val: unknown): val is Date {
33
- return is(val, 'Date')
34
- }
35
-
36
- export function isNull(val: unknown): val is null {
37
- return val === null
38
- }
39
-
40
- export function isNullAndUnDef(val: unknown): val is null | undefined {
41
- return isUnDef(val) && isNull(val)
42
- }
43
-
44
- export function isNullOrUnDef(val: unknown): val is null | undefined {
45
- return isUnDef(val) || isNull(val)
46
- }
47
-
48
- export function isNumber(val: unknown): val is number {
49
- return is(val, 'Number')
50
- }
51
-
52
- export function isPromise<T = any>(val: unknown): val is Promise<T> {
53
- return (
54
- is(val, 'Promise')
55
- && isObject(val)
56
- && isFunction(val.then)
57
- && isFunction(val.catch)
58
- )
59
- }
60
-
61
- export function isString(val: unknown): val is string {
62
- return is(val, 'String')
63
- }
64
-
65
- export function isFunction(val: unknown): val is Function {
66
- return typeof val === 'function'
67
- }
68
-
69
- export function isBoolean(val: unknown): val is boolean {
70
- return is(val, 'Boolean')
71
- }
72
-
73
- export function isRegExp(val: unknown): val is RegExp {
74
- return is(val, 'RegExp')
75
- }
76
-
77
- export function isArray(val: any): val is Array<any> {
78
- return val && Array.isArray(val)
79
- }
80
-
81
- export function isWindow(val: any): val is Window {
82
- return typeof window !== 'undefined' && is(val, 'Window')
83
- }
84
-
85
- export function isElement(val: unknown): val is Element {
86
- return isObject(val) && !!val.tagName
87
- }
88
-
89
- export function isMap(val: unknown): val is Map<any, any> {
90
- return is(val, 'Map')
91
- }
92
-
93
- export const isServer = typeof window === 'undefined'
94
-
95
- export const isClient = !isServer
96
-
97
- export function isValidKey(
98
- key: string | number | symbol,
99
- object: object
100
- ): key is keyof typeof object {
101
- return key in object
102
- }
@@ -1,37 +0,0 @@
1
- import debug from 'debug'
2
-
3
- type Color = 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'error'
4
-
5
- const colorList: Color[] = ['primary', 'success', 'info', 'warning', 'danger', 'error']
6
-
7
- const colorMap: Record<Color, string> = {
8
- primary: '#2d8cf0',
9
- success: '#19be6b',
10
- info: '#909399',
11
- warning: '#ff9900',
12
- danger: '#35495E',
13
- error: '#FF0000'
14
- }
15
-
16
- const getColor = (type: Color) => colorMap[type]
17
-
18
- function createLog<T extends any[]>(fn: (type: Color, ...args: T) => void): Record<Color, (...args: T) => void> {
19
- return colorList.reduce((logs, type) => {
20
- logs[type] = (...args: T) => fn(type, ...args)
21
- return logs
22
- }, {} as Record<Color, (...args: T) => void>)
23
- }
24
-
25
- function initLog(type: Color, model: string, ns: string, msg: string, ...args: any[]) {
26
- const color = getColor(type)
27
- const logger = debug(model)
28
- const config = `%c ${ns} %c ${msg} %c ${args.length ? '%o' : ''}`
29
- const title = `background:${color};border:1px solid ${color}; padding: 1px; border-radius: 4px 0 0 4px; color: #fff;`
30
- const content = `border:1px solid ${color}; padding: 1px; border-radius: 0 4px 4px 0; color: ${color};`
31
- const joinColor = 'background:transparent'
32
-
33
- logger(config, title, content, joinColor, ...args)
34
- localStorage.debug = `${model}*`
35
- }
36
-
37
- export const logger = createLog(initLog)
@@ -1,145 +0,0 @@
1
- import { getI18n } from '@/lang'
2
-
3
- const { t } = getI18n().global
4
-
5
- /**
6
- * 获取当天日期
7
- * @param cutOff 分隔号
8
- * @returns {string}
9
- */
10
- export function getToday(cutOff: string = '-'): string {
11
- const dateObj = new Date()
12
- return formatDay(dateObj).join(cutOff)
13
- }
14
-
15
- /**
16
- * 获取传入日期的过后几天日期数组
17
- * @param today
18
- * @param daysCount
19
- * @param cutOff
20
- * @returns {string[]}
21
- */
22
- export function getNextDays({ today, daysCount, cutOff = '-' }: { today?: string, daysCount: number, cutOff?: string }): string[] {
23
- if (!today)
24
- today = getToday('/')
25
-
26
- const dateObj = new Date(today)
27
- const arr = [formatDay(dateObj).join(cutOff)]
28
- for (let i = 0; i < daysCount; i++) {
29
- const days = dateObj.setDate(dateObj.getDate() + 1)
30
- arr.push(formatDay(new Date(days)).join(cutOff))
31
- }
32
- return arr
33
- }
34
-
35
- /**
36
- * 获取传入日期的前几天日期数组
37
- * @param today
38
- * @param daysCount
39
- * @param cutOff
40
- * @returns {string[]}
41
- */
42
- export function getBeforeDays({ today, daysCount, cutOff = '-' }: { today?: string, daysCount: number, cutOff?: string }): string[] {
43
- if (!today)
44
- today = getToday('/')
45
-
46
- const dateObj = new Date(today)
47
- const arr = [formatDay(dateObj).join(cutOff)]
48
- for (let i = 0; i < daysCount; i++) {
49
- const days = dateObj.setDate(dateObj.getDate() - 1)
50
- arr.push(formatDay(new Date(days)).join(cutOff))
51
- }
52
- return arr
53
- }
54
-
55
- /**
56
- * 传入date对象 返回格式化后的数组
57
- * @param dateObj
58
- * @returns {[number, number, number]}
59
- */
60
- export function formatDay(dateObj: Date): [number, number, number] {
61
- const year = dateObj.getFullYear()
62
- const month = dateObj.getMonth() + 1
63
- const date = dateObj.getDate()
64
- return [year, month, date]
65
- }
66
-
67
- export function formatTime(dateObj: Date): string[] {
68
- const h = dateObj.getHours()
69
- let m: string | number = dateObj.getMinutes()
70
- let s: string | number = dateObj.getSeconds()
71
- if (m < 10)
72
- m = `0${m}`
73
- if (s < 10)
74
- s = `0${s}`
75
-
76
- return [h, m, s].map(String)
77
- }
78
-
79
- export function getCurDtm(cutOff: string = '-'): string {
80
- return `${getToday(cutOff)} ${this.formatTime(new Date()).join(':')}`
81
- }
82
-
83
- /**
84
- * 传入秒数 返回时分秒
85
- * @param value
86
- * @returns {string}
87
- */
88
- export function formatSeconds(value: number): string {
89
- let theTime = Math.floor(value) // 秒
90
- let middle = 0 // 分
91
- let hour = 0 // 小时
92
-
93
- if (theTime > 60) {
94
- middle = Math.floor(theTime / 60)
95
- theTime = theTime % 60
96
- if (middle > 60) {
97
- hour = Math.floor(middle / 60)
98
- middle = middle % 60
99
- }
100
- }
101
-
102
- let result = theTime < 10 ? `00:0${theTime}` : `00:${theTime}`
103
- if (middle > 0)
104
- result = middle < 10 ? `0${middle}:${result}` : `${middle}:${result}`
105
-
106
- if (hour > 0)
107
- result = `${hour}:${result}`
108
-
109
- return result
110
- }
111
-
112
- // 转化时间
113
- export function formatTimeFn(number: number, format: string): string {
114
- const time = new Date(number)
115
- const newArr = []
116
- const formatArr = ['Y', 'M', 'D', 'day', 'h', 'm', 's']
117
- const arrWeek = [
118
- t('sunday'),
119
- t('monday'),
120
- t('tuesday'),
121
- t('wednesday'),
122
- t('thursday'),
123
- t('sundayFriday'),
124
- t('saturday')
125
- ]
126
-
127
- const formatNumber = (n) => {
128
- n = n.toString()
129
- return n[1] ? n : `0${n}`
130
- }
131
-
132
- newArr.push(time.getFullYear())
133
- newArr.push(formatNumber(time.getMonth() + 1))
134
- newArr.push(formatNumber(time.getHours()))
135
- newArr.push(arrWeek[time.getDay()])
136
- newArr.push(formatNumber(time.getDate()))
137
- newArr.push(formatNumber(time.getMinutes()))
138
- newArr.push(formatNumber(time.getSeconds()))
139
- newArr.push(formatNumber(time.getDay()))
140
-
141
- for (const i in newArr)
142
- format = format.replace(formatArr[i], newArr[i])
143
-
144
- return format
145
- }
@@ -1,6 +0,0 @@
1
- // 获取子应用数据
2
- export function getMicroAppData(id: string): Window | null {
3
- const iframeElement = window.document.querySelector(`iframe[name="${id}"]`) as HTMLIFrameElement | null
4
-
5
- return iframeElement ? iframeElement.contentWindow : null
6
- }
@@ -1,93 +0,0 @@
1
- import { defineComponent as _, ref as p, resolveComponent as i, openBlock as g, createElementBlock as v, Fragment as h, createElementVNode as r, unref as x, createVNode as t, withCtx as c, createTextVNode as s } from "vue";
2
- import { f as C } from "./command-center-v3-common-BbSatiTO.js";
3
- const w = { class: "flex flex-col items-center justify-center gap-6" }, y = ["src"], b = { class: "flex items-center gap-x-3" }, S = /* @__PURE__ */ _({
4
- __name: "vue-cropper-demo",
5
- setup(B) {
6
- const e = p(), a = p("https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg");
7
- async function f() {
8
- const n = {
9
- img: a.value
10
- };
11
- await e.value.onShowModal(n), a.value = await e.value.getCropData();
12
- }
13
- function u() {
14
- a.value = "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg";
15
- }
16
- async function d(n) {
17
- const o = {
18
- img: await e.value.getBlobToData(n),
19
- outputType: "png",
20
- // 裁剪生成图片的格式
21
- canScale: !0,
22
- // 图片是否允许滚轮缩放
23
- fixedBox: !0,
24
- // 固定截图框大小 不允许改变
25
- infoTrue: !1,
26
- // 是否开启截图框宽高固定比例
27
- autoCropWidth: 70,
28
- autoCropHeight: 70,
29
- centerBox: !1,
30
- original: !0,
31
- fixed: !1
32
- };
33
- await e.value.onShowModal(o);
34
- const l = await e.value.getCropBlob();
35
- console.log(l);
36
- }
37
- return (n, m) => {
38
- const o = i("el-button"), l = i("el-upload");
39
- return g(), v(h, null, [
40
- r("div", w, [
41
- r("img", {
42
- src: x(a),
43
- class: "rounded-xl"
44
- }, null, 8, y),
45
- t(l, {
46
- accept: ".png,.jpg,.gif",
47
- "before-upload": d,
48
- action: "",
49
- class: "relative group overflow-hidden",
50
- "show-file-list": !1
51
- }, {
52
- default: c(() => [
53
- t(o, { type: "primary" }, {
54
- default: c(() => [
55
- s(" 上传图片 ")
56
- ]),
57
- _: 1
58
- })
59
- ]),
60
- _: 1
61
- }),
62
- r("div", b, [
63
- t(o, {
64
- type: "primary",
65
- onClick: f
66
- }, {
67
- default: c(() => [
68
- s(" 图片裁剪 ")
69
- ]),
70
- _: 1
71
- }),
72
- t(o, {
73
- type: "primary",
74
- onClick: u
75
- }, {
76
- default: c(() => [
77
- s(" 还原 ")
78
- ]),
79
- _: 1
80
- })
81
- ])
82
- ]),
83
- t(C, {
84
- ref_key: "vueCropper",
85
- ref: e
86
- }, null, 512)
87
- ], 64);
88
- };
89
- }
90
- });
91
- export {
92
- S as default
93
- };