zxq-com 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/dist/index.d.ts +80 -0
- package/dist/zxq-com.css +2 -0
- package/dist/zxq-com.js +101 -0
- package/dist/zxq-com.umd.cjs +1 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import { ComponentOptionsMixin } from 'vue';
|
|
3
|
+
import { ComponentProvideOptions } from 'vue';
|
|
4
|
+
import { DefineComponent } from 'vue';
|
|
5
|
+
import { Fn } from '@vueuse/core';
|
|
6
|
+
import { PublicProps } from 'vue';
|
|
7
|
+
import { Ref } from 'vue';
|
|
8
|
+
import { ShallowRef } from 'vue';
|
|
9
|
+
import { WebSocketStatus } from '@vueuse/core';
|
|
10
|
+
|
|
11
|
+
declare const __VLS_component: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, HTMLButtonElement>;
|
|
12
|
+
|
|
13
|
+
declare function __VLS_template(): {
|
|
14
|
+
attrs: Partial<{}>;
|
|
15
|
+
slots: {
|
|
16
|
+
default?(_: {}): any;
|
|
17
|
+
};
|
|
18
|
+
refs: {};
|
|
19
|
+
rootEl: HTMLButtonElement;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
23
|
+
|
|
24
|
+
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
25
|
+
new (): {
|
|
26
|
+
$slots: S;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
declare const close_2: (code?: number, reason?: string) => void;
|
|
31
|
+
export { close_2 as close }
|
|
32
|
+
|
|
33
|
+
export declare const data: Ref<any, any>;
|
|
34
|
+
|
|
35
|
+
declare const _default: {
|
|
36
|
+
install(app: App): void;
|
|
37
|
+
};
|
|
38
|
+
export default _default;
|
|
39
|
+
|
|
40
|
+
export declare const EVENT_TYPE: {
|
|
41
|
+
readonly DEV1: "dev-1";
|
|
42
|
+
readonly DEV2: "dev-2";
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
declare const open_2: Fn;
|
|
46
|
+
export { open_2 as open }
|
|
47
|
+
|
|
48
|
+
export declare const send: (data: string | ArrayBuffer | Blob, useBuffer?: boolean) => boolean;
|
|
49
|
+
|
|
50
|
+
declare const status_2: ShallowRef<WebSocketStatus>;
|
|
51
|
+
export { status_2 as status }
|
|
52
|
+
|
|
53
|
+
export declare function useWs<T = any>(event: WsMessageEvent): UseWsResult<T>;
|
|
54
|
+
|
|
55
|
+
export declare interface UseWsResult<T> {
|
|
56
|
+
on: (callback: (payload: T) => void) => void;
|
|
57
|
+
off: () => void;
|
|
58
|
+
once: (callback: (payload: T) => void) => void;
|
|
59
|
+
emit: (msg: WsMessage) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export declare interface WsConfig {
|
|
63
|
+
url: string;
|
|
64
|
+
trustIp?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export declare interface WsMessage {
|
|
68
|
+
event: WsMessageEvent;
|
|
69
|
+
payload: any;
|
|
70
|
+
sourceIp?: string;
|
|
71
|
+
timestamp?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export declare type WsMessageEvent = typeof EVENT_TYPE[keyof typeof EVENT_TYPE];
|
|
75
|
+
|
|
76
|
+
export declare function zwqWs(_app: any, config: WsConfig): void;
|
|
77
|
+
|
|
78
|
+
export declare const ZxqButton: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
79
|
+
|
|
80
|
+
export { }
|
package/dist/zxq-com.css
ADDED
package/dist/zxq-com.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createElementBlock, defineComponent, onBeforeUnmount, openBlock, ref, renderSlot, watch } from "vue";
|
|
2
|
+
import { useWebSocket } from "@vueuse/core";
|
|
3
|
+
var _hoisted_1 = { class: "zxq-button" }, Button_default = /* @__PURE__ */ defineComponent({
|
|
4
|
+
name: "ZxqButton",
|
|
5
|
+
__name: "Button",
|
|
6
|
+
setup(v) {
|
|
7
|
+
return (v, y) => (openBlock(), createElementBlock("button", _hoisted_1, [renderSlot(v.$slots, "default")]));
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
const EVENT_TYPE = {
|
|
11
|
+
DEV1: "dev-1",
|
|
12
|
+
DEV2: "dev-2"
|
|
13
|
+
};
|
|
14
|
+
var urlRef = ref();
|
|
15
|
+
const { status, data, send, close, open } = useWebSocket(urlRef, {
|
|
16
|
+
immediate: !1,
|
|
17
|
+
autoConnect: !1,
|
|
18
|
+
heartbeat: {
|
|
19
|
+
message: "ping",
|
|
20
|
+
interval: 5e3,
|
|
21
|
+
pongTimeout: 15e3
|
|
22
|
+
},
|
|
23
|
+
autoReconnect: {
|
|
24
|
+
retries: 3,
|
|
25
|
+
delay: 1e4,
|
|
26
|
+
onFailed() {
|
|
27
|
+
console.error("超过重连次数");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var subscribeMap = /* @__PURE__ */ new Map();
|
|
32
|
+
function zwqWs(e, v) {
|
|
33
|
+
urlRef.value || (urlRef.value = v.url, open()), watch(status, (e) => {
|
|
34
|
+
log("ws status", e);
|
|
35
|
+
}), watch(data, (e) => {
|
|
36
|
+
if (e !== "pong") try {
|
|
37
|
+
let { sourceIp: y, event: b, payload: x } = JSON.parse(e);
|
|
38
|
+
if (v?.trustIp && y !== v.trustIp) return;
|
|
39
|
+
let S = subscribeMap.get(b);
|
|
40
|
+
S && S.forEach(({ fn: e, off: v }) => {
|
|
41
|
+
e(x), v && v();
|
|
42
|
+
});
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.error("ws 数据格式有误", e);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function useWs(e) {
|
|
49
|
+
status.value === "CLOSED" && urlRef.value && open();
|
|
50
|
+
let v = getUUID();
|
|
51
|
+
function b(y) {
|
|
52
|
+
log("ws on");
|
|
53
|
+
let b = subscribeMap.get(e);
|
|
54
|
+
if (b) b.set(v, { fn: y });
|
|
55
|
+
else {
|
|
56
|
+
let b = (/* @__PURE__ */ new Map()).set(v, { fn: y });
|
|
57
|
+
subscribeMap.set(e, b);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function x() {
|
|
61
|
+
log("ws off");
|
|
62
|
+
let y = subscribeMap.get(e);
|
|
63
|
+
y && y.has(v) && (y.delete(v), y.size === 0 && subscribeMap.delete(e));
|
|
64
|
+
}
|
|
65
|
+
function S(y) {
|
|
66
|
+
log("ws once");
|
|
67
|
+
let b = subscribeMap.get(e);
|
|
68
|
+
if (b) b.set(v, { fn: y });
|
|
69
|
+
else {
|
|
70
|
+
let b = (/* @__PURE__ */ new Map()).set(v, {
|
|
71
|
+
fn: y,
|
|
72
|
+
off: x
|
|
73
|
+
});
|
|
74
|
+
subscribeMap.set(e, b);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
onBeforeUnmount(() => {
|
|
78
|
+
x();
|
|
79
|
+
});
|
|
80
|
+
function C(e) {
|
|
81
|
+
send(JSON.stringify(e));
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
on: b,
|
|
85
|
+
off: x,
|
|
86
|
+
once: S,
|
|
87
|
+
emit: C
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function getUUID(e = "") {
|
|
91
|
+
return e + (crypto?.randomUUID?.() || `${Date.now()}_${Math.random().toString(16).slice(2)}`);
|
|
92
|
+
}
|
|
93
|
+
function log(...e) {
|
|
94
|
+
console.log("【zxqWs】", ...e);
|
|
95
|
+
}
|
|
96
|
+
var components = [Button_default], src_default = { install(e) {
|
|
97
|
+
components.forEach((v) => {
|
|
98
|
+
e.component(v.name, v);
|
|
99
|
+
});
|
|
100
|
+
} };
|
|
101
|
+
export { EVENT_TYPE, Button_default as ZxqButton, close, data, src_default as default, open, send, status, useWs, zwqWs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`),require(`@vueuse/core`)):typeof define==`function`&&define.amd?define([`exports`,`vue`,`@vueuse/core`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ZxqCom={},e.Vue,e.VueUse))})(this,function(e,t,n){Object.defineProperty(e,`__esModule`,{value:!0});var r={class:`zxq-button`},i=(0,t.defineComponent)({name:`ZxqButton`,__name:`Button`,setup(e){return(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`button`,r,[(0,t.renderSlot)(e.$slots,`default`)]))}});let a={DEV1:`dev-1`,DEV2:`dev-2`};var o=(0,t.ref)();let{status:s,data:c,send:l,close:u,open:d}=(0,n.useWebSocket)(o,{immediate:!1,autoConnect:!1,heartbeat:{message:`ping`,interval:5e3,pongTimeout:15e3},autoReconnect:{retries:3,delay:1e4,onFailed(){console.error(`超过重连次数`)}}});var f=new Map;function p(e,n){o.value||(o.value=n.url,d()),(0,t.watch)(s,e=>{g(`ws status`,e)}),(0,t.watch)(c,e=>{if(e!==`pong`)try{let{sourceIp:t,event:r,payload:i}=JSON.parse(e);if(n?.trustIp&&t!==n.trustIp)return;let a=f.get(r);a&&a.forEach(({fn:e,off:t})=>{e(i),t&&t()})}catch(e){console.error(`ws 数据格式有误`,e)}})}function m(e){s.value===`CLOSED`&&o.value&&d();let n=h();function r(t){g(`ws on`);let r=f.get(e);if(r)r.set(n,{fn:t});else{let r=new Map().set(n,{fn:t});f.set(e,r)}}function i(){g(`ws off`);let t=f.get(e);t&&t.has(n)&&(t.delete(n),t.size===0&&f.delete(e))}function a(t){g(`ws once`);let r=f.get(e);if(r)r.set(n,{fn:t});else{let r=new Map().set(n,{fn:t,off:i});f.set(e,r)}}(0,t.onBeforeUnmount)(()=>{i()});function c(e){l(JSON.stringify(e))}return{on:r,off:i,once:a,emit:c}}function h(e=``){return e+(crypto?.randomUUID?.()||`${Date.now()}_${Math.random().toString(16).slice(2)}`)}function g(...e){console.log(`【zxqWs】`,...e)}var _=[i];e.EVENT_TYPE=a,e.ZxqButton=i,e.close=u,e.data=c,e.default={install(e){_.forEach(t=>{e.component(t.name,t)})}},e.open=d,e.send=l,e.status=s,e.useWs=m,e.zwqWs=p});
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zxq-com",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/zxq-com.umd.cjs",
|
|
6
|
+
"module": "./dist/zxq-com.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/zxq-com.js",
|
|
11
|
+
"require": "./dist/zxq-com.umd.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./style.css": "./dist/style.css"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"*.css",
|
|
21
|
+
"*.vue"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vue-tsc -b && vite build",
|
|
25
|
+
"dev": "vite build --watch"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@vueuse/core": "^14.1.0",
|
|
29
|
+
"vue": "^3.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^24.10.9",
|
|
33
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
34
|
+
"@vue/tsconfig": "^0.8.1",
|
|
35
|
+
"typescript": "~5.9.3",
|
|
36
|
+
"unplugin-auto-import": "^21.0.0",
|
|
37
|
+
"unplugin-vue-components": "^31.0.0",
|
|
38
|
+
"vite": "npm:rolldown-vite@7.2.5",
|
|
39
|
+
"vite-plugin-dts": "^4.3.0",
|
|
40
|
+
"vue": "^3.5.24",
|
|
41
|
+
"vue-tsc": "^3.1.4"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"naive-ui": "^2.43.2"
|
|
45
|
+
}
|
|
46
|
+
}
|