@hlw-uni/mp-vue 1.0.0
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/components/hlw-avatar/index.d.ts +7 -0
- package/dist/components/hlw-empty/index.d.ts +2 -0
- package/dist/components/hlw-loading/index.d.ts +2 -0
- package/dist/components/hlw-menu-list/index.d.ts +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +192 -0
- package/dist/index.mjs +189 -0
- package/package.json +41 -0
- package/src/components/hlw-ad/index.vue +56 -0
- package/src/components/hlw-avatar/index.ts +52 -0
- package/src/components/hlw-avatar/index.vue +4 -0
- package/src/components/hlw-empty/index.ts +34 -0
- package/src/components/hlw-empty/index.vue +4 -0
- package/src/components/hlw-loading/index.ts +29 -0
- package/src/components/hlw-loading/index.vue +4 -0
- package/src/components/hlw-menu-list/index.ts +64 -0
- package/src/components/hlw-menu-list/index.vue +4 -0
- package/src/index.ts +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hlw-uni/mp-vue — Vue 组件库统一导出
|
|
3
|
+
*/
|
|
4
|
+
export { default as HlwAd } from './components/hlw-ad/index.vue';
|
|
5
|
+
export { default as HlwAvatar } from './components/hlw-avatar/index';
|
|
6
|
+
export { default as HlwEmpty } from './components/hlw-empty/index';
|
|
7
|
+
export { default as HlwLoading } from './components/hlw-loading/index';
|
|
8
|
+
export { default as HlwMenuList, type MenuItem } from './components/hlw-menu-list/index';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue")) : typeof define === "function" && define.amd ? define(["exports", "vue"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HlwUniVue = {}, global.vue));
|
|
3
|
+
})(this, function(exports2, vue) {
|
|
4
|
+
"use strict";
|
|
5
|
+
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
6
|
+
...{ name: "HlwAd" },
|
|
7
|
+
__name: "index",
|
|
8
|
+
props: {
|
|
9
|
+
unitId: {}
|
|
10
|
+
},
|
|
11
|
+
emits: ["load", "close", "error"],
|
|
12
|
+
setup(__props, { emit: __emit }) {
|
|
13
|
+
const emit = __emit;
|
|
14
|
+
function onLoad(event) {
|
|
15
|
+
emit("load", event);
|
|
16
|
+
}
|
|
17
|
+
function onClose(event) {
|
|
18
|
+
emit("close", event);
|
|
19
|
+
}
|
|
20
|
+
function onError(event) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
console.error("[HlwAd] 广告错误:", (_a = event == null ? void 0 : event.detail) == null ? void 0 : _a.errCode, (_b = event == null ? void 0 : event.detail) == null ? void 0 : _b.errMsg);
|
|
23
|
+
emit("error", event);
|
|
24
|
+
}
|
|
25
|
+
return (_ctx, _cache) => {
|
|
26
|
+
const _component_ad = vue.resolveComponent("ad");
|
|
27
|
+
return vue.openBlock(), vue.createBlock(_component_ad, {
|
|
28
|
+
"unit-id": __props.unitId,
|
|
29
|
+
onLoad,
|
|
30
|
+
onClose,
|
|
31
|
+
onError
|
|
32
|
+
}, null, 8, ["unit-id"]);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const index$3 = vue.defineComponent({
|
|
37
|
+
name: "Avatar",
|
|
38
|
+
props: {
|
|
39
|
+
src: { type: String },
|
|
40
|
+
name: { type: String },
|
|
41
|
+
size: { type: String, default: "medium" }
|
|
42
|
+
},
|
|
43
|
+
setup(props) {
|
|
44
|
+
const loadError = vue.ref(false);
|
|
45
|
+
const initial = vue.computed(() => {
|
|
46
|
+
if (!props.name)
|
|
47
|
+
return "?";
|
|
48
|
+
return props.name.charAt(0).toUpperCase();
|
|
49
|
+
});
|
|
50
|
+
function onError() {
|
|
51
|
+
loadError.value = true;
|
|
52
|
+
}
|
|
53
|
+
return () => {
|
|
54
|
+
const sizeClass = `hlw-avatar--${props.size}`;
|
|
55
|
+
return (
|
|
56
|
+
// @ts-ignore - uni app nodes
|
|
57
|
+
h("view", { class: `hlw-avatar ${sizeClass}` }, [
|
|
58
|
+
props.src && !loadError.value ? (
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
h("image", {
|
|
61
|
+
class: "hlw-avatar__image",
|
|
62
|
+
src: props.src,
|
|
63
|
+
mode: "aspectFill",
|
|
64
|
+
onError
|
|
65
|
+
})
|
|
66
|
+
) : (
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
h("view", { class: "hlw-avatar__placeholder" }, [
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
h("text", { class: "hlw-avatar__initial" }, initial.value)
|
|
71
|
+
])
|
|
72
|
+
)
|
|
73
|
+
])
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const index$2 = vue.defineComponent({
|
|
79
|
+
name: "Empty",
|
|
80
|
+
props: {
|
|
81
|
+
text: { type: String },
|
|
82
|
+
image: { type: String }
|
|
83
|
+
},
|
|
84
|
+
setup(props) {
|
|
85
|
+
const slots = vue.useSlots();
|
|
86
|
+
return () => {
|
|
87
|
+
var _a;
|
|
88
|
+
return (
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
h("view", { class: "hlw-empty" }, [
|
|
91
|
+
props.image ? (
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
h("image", { class: "hlw-empty__image", src: props.image, mode: "aspectFit" })
|
|
94
|
+
) : (
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
h("view", { class: "hlw-empty__icon" }, [
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
h("text", "📦")
|
|
99
|
+
])
|
|
100
|
+
),
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
h("text", { class: "hlw-empty__text" }, props.text || "暂无数据"),
|
|
103
|
+
(_a = slots.default) == null ? void 0 : _a.call(slots)
|
|
104
|
+
])
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const index$1 = vue.defineComponent({
|
|
110
|
+
name: "Loading",
|
|
111
|
+
props: {
|
|
112
|
+
text: { type: String }
|
|
113
|
+
},
|
|
114
|
+
setup(props) {
|
|
115
|
+
return () => {
|
|
116
|
+
const dots = Array.from(
|
|
117
|
+
{ length: 12 },
|
|
118
|
+
(_, i) => (
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
h("view", { key: i + 1, class: "hlw-loading__dot" })
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
return (
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
h("view", { class: "hlw-loading" }, [
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
h("view", { class: "hlw-loading__spinner" }, dots),
|
|
128
|
+
props.text ? (
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
h("text", { class: "hlw-loading__text" }, props.text)
|
|
131
|
+
) : null
|
|
132
|
+
])
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const index = vue.defineComponent({
|
|
138
|
+
name: "MenuList",
|
|
139
|
+
props: {
|
|
140
|
+
items: { type: Array, required: true }
|
|
141
|
+
},
|
|
142
|
+
emits: ["click"],
|
|
143
|
+
setup(props, { emit }) {
|
|
144
|
+
function onTap(item) {
|
|
145
|
+
if (item.url) {
|
|
146
|
+
uni.navigateTo({ url: item.url });
|
|
147
|
+
} else if (item.action) {
|
|
148
|
+
item.action();
|
|
149
|
+
}
|
|
150
|
+
emit("click", item);
|
|
151
|
+
}
|
|
152
|
+
return () => {
|
|
153
|
+
const items = props.items.map(
|
|
154
|
+
(item) => (
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
h("view", {
|
|
157
|
+
class: "hlw-menu-list__item",
|
|
158
|
+
key: item.key,
|
|
159
|
+
onClick: () => onTap(item)
|
|
160
|
+
}, [
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
h("view", { class: "hlw-menu-list__left" }, [
|
|
163
|
+
item.icon ? (
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
h("text", { class: "hlw-menu-list__icon" }, item.icon)
|
|
166
|
+
) : null,
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
h("text", { class: "hlw-menu-list__label" }, item.label)
|
|
169
|
+
]),
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
h("view", { class: "hlw-menu-list__right" }, [
|
|
172
|
+
item.value ? (
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
h("text", { class: "hlw-menu-list__value" }, item.value)
|
|
175
|
+
) : null,
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
h("text", { class: "hlw-menu-list__arrow" }, "›")
|
|
178
|
+
])
|
|
179
|
+
])
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
return h("view", { class: "hlw-menu-list" }, items);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
exports2.HlwAd = _sfc_main;
|
|
187
|
+
exports2.HlwAvatar = index$3;
|
|
188
|
+
exports2.HlwEmpty = index$2;
|
|
189
|
+
exports2.HlwLoading = index$1;
|
|
190
|
+
exports2.HlwMenuList = index;
|
|
191
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
192
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { defineComponent, resolveComponent, openBlock, createBlock, ref, computed, useSlots } from "vue";
|
|
2
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
3
|
+
...{ name: "HlwAd" },
|
|
4
|
+
__name: "index",
|
|
5
|
+
props: {
|
|
6
|
+
unitId: {}
|
|
7
|
+
},
|
|
8
|
+
emits: ["load", "close", "error"],
|
|
9
|
+
setup(__props, { emit: __emit }) {
|
|
10
|
+
const emit = __emit;
|
|
11
|
+
function onLoad(event) {
|
|
12
|
+
emit("load", event);
|
|
13
|
+
}
|
|
14
|
+
function onClose(event) {
|
|
15
|
+
emit("close", event);
|
|
16
|
+
}
|
|
17
|
+
function onError(event) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
console.error("[HlwAd] 广告错误:", (_a = event == null ? void 0 : event.detail) == null ? void 0 : _a.errCode, (_b = event == null ? void 0 : event.detail) == null ? void 0 : _b.errMsg);
|
|
20
|
+
emit("error", event);
|
|
21
|
+
}
|
|
22
|
+
return (_ctx, _cache) => {
|
|
23
|
+
const _component_ad = resolveComponent("ad");
|
|
24
|
+
return openBlock(), createBlock(_component_ad, {
|
|
25
|
+
"unit-id": __props.unitId,
|
|
26
|
+
onLoad,
|
|
27
|
+
onClose,
|
|
28
|
+
onError
|
|
29
|
+
}, null, 8, ["unit-id"]);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const index$3 = defineComponent({
|
|
34
|
+
name: "Avatar",
|
|
35
|
+
props: {
|
|
36
|
+
src: { type: String },
|
|
37
|
+
name: { type: String },
|
|
38
|
+
size: { type: String, default: "medium" }
|
|
39
|
+
},
|
|
40
|
+
setup(props) {
|
|
41
|
+
const loadError = ref(false);
|
|
42
|
+
const initial = computed(() => {
|
|
43
|
+
if (!props.name)
|
|
44
|
+
return "?";
|
|
45
|
+
return props.name.charAt(0).toUpperCase();
|
|
46
|
+
});
|
|
47
|
+
function onError() {
|
|
48
|
+
loadError.value = true;
|
|
49
|
+
}
|
|
50
|
+
return () => {
|
|
51
|
+
const sizeClass = `hlw-avatar--${props.size}`;
|
|
52
|
+
return (
|
|
53
|
+
// @ts-ignore - uni app nodes
|
|
54
|
+
h("view", { class: `hlw-avatar ${sizeClass}` }, [
|
|
55
|
+
props.src && !loadError.value ? (
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
h("image", {
|
|
58
|
+
class: "hlw-avatar__image",
|
|
59
|
+
src: props.src,
|
|
60
|
+
mode: "aspectFill",
|
|
61
|
+
onError
|
|
62
|
+
})
|
|
63
|
+
) : (
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
h("view", { class: "hlw-avatar__placeholder" }, [
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
h("text", { class: "hlw-avatar__initial" }, initial.value)
|
|
68
|
+
])
|
|
69
|
+
)
|
|
70
|
+
])
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const index$2 = defineComponent({
|
|
76
|
+
name: "Empty",
|
|
77
|
+
props: {
|
|
78
|
+
text: { type: String },
|
|
79
|
+
image: { type: String }
|
|
80
|
+
},
|
|
81
|
+
setup(props) {
|
|
82
|
+
const slots = useSlots();
|
|
83
|
+
return () => {
|
|
84
|
+
var _a;
|
|
85
|
+
return (
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
h("view", { class: "hlw-empty" }, [
|
|
88
|
+
props.image ? (
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
h("image", { class: "hlw-empty__image", src: props.image, mode: "aspectFit" })
|
|
91
|
+
) : (
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
h("view", { class: "hlw-empty__icon" }, [
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
h("text", "📦")
|
|
96
|
+
])
|
|
97
|
+
),
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
h("text", { class: "hlw-empty__text" }, props.text || "暂无数据"),
|
|
100
|
+
(_a = slots.default) == null ? void 0 : _a.call(slots)
|
|
101
|
+
])
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const index$1 = defineComponent({
|
|
107
|
+
name: "Loading",
|
|
108
|
+
props: {
|
|
109
|
+
text: { type: String }
|
|
110
|
+
},
|
|
111
|
+
setup(props) {
|
|
112
|
+
return () => {
|
|
113
|
+
const dots = Array.from(
|
|
114
|
+
{ length: 12 },
|
|
115
|
+
(_, i) => (
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
h("view", { key: i + 1, class: "hlw-loading__dot" })
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
return (
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
h("view", { class: "hlw-loading" }, [
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
h("view", { class: "hlw-loading__spinner" }, dots),
|
|
125
|
+
props.text ? (
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
h("text", { class: "hlw-loading__text" }, props.text)
|
|
128
|
+
) : null
|
|
129
|
+
])
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const index = defineComponent({
|
|
135
|
+
name: "MenuList",
|
|
136
|
+
props: {
|
|
137
|
+
items: { type: Array, required: true }
|
|
138
|
+
},
|
|
139
|
+
emits: ["click"],
|
|
140
|
+
setup(props, { emit }) {
|
|
141
|
+
function onTap(item) {
|
|
142
|
+
if (item.url) {
|
|
143
|
+
uni.navigateTo({ url: item.url });
|
|
144
|
+
} else if (item.action) {
|
|
145
|
+
item.action();
|
|
146
|
+
}
|
|
147
|
+
emit("click", item);
|
|
148
|
+
}
|
|
149
|
+
return () => {
|
|
150
|
+
const items = props.items.map(
|
|
151
|
+
(item) => (
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
h("view", {
|
|
154
|
+
class: "hlw-menu-list__item",
|
|
155
|
+
key: item.key,
|
|
156
|
+
onClick: () => onTap(item)
|
|
157
|
+
}, [
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
h("view", { class: "hlw-menu-list__left" }, [
|
|
160
|
+
item.icon ? (
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
h("text", { class: "hlw-menu-list__icon" }, item.icon)
|
|
163
|
+
) : null,
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
h("text", { class: "hlw-menu-list__label" }, item.label)
|
|
166
|
+
]),
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
h("view", { class: "hlw-menu-list__right" }, [
|
|
169
|
+
item.value ? (
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
h("text", { class: "hlw-menu-list__value" }, item.value)
|
|
172
|
+
) : null,
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
h("text", { class: "hlw-menu-list__arrow" }, "›")
|
|
175
|
+
])
|
|
176
|
+
])
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
return h("view", { class: "hlw-menu-list" }, items);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
export {
|
|
184
|
+
_sfc_main as HlwAd,
|
|
185
|
+
index$3 as HlwAvatar,
|
|
186
|
+
index$2 as HlwEmpty,
|
|
187
|
+
index$1 as HlwLoading,
|
|
188
|
+
index as HlwMenuList
|
|
189
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hlw-uni/mp-vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "hlw-uni Vue 组件库 — 供小程序业务方使用的 UI 组件集合",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "vite build",
|
|
21
|
+
"dev": "vite build --watch"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"vue": ">=3.4.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@dcloudio/types": "^3.4.8",
|
|
31
|
+
"@types/node": "^20.11.0",
|
|
32
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
33
|
+
"typescript": "^4.9.4",
|
|
34
|
+
"vite": "5.2.8",
|
|
35
|
+
"vite-plugin-dts": "^4.5.4",
|
|
36
|
+
"vue": "^3.4.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@hlw-uni/mp-core": "^1.0.6"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* HlwAd — 小程序信息流 / Banner 广告组件
|
|
4
|
+
*
|
|
5
|
+
* 对小程序原生 <ad> 组件的封装。
|
|
6
|
+
* 支持微信小程序、抖音小程序等,由 uni-app 编译器适配各平台。
|
|
7
|
+
*
|
|
8
|
+
* Props:
|
|
9
|
+
* unitId - 广告单元 ID(各平台在广告后台申请)
|
|
10
|
+
*
|
|
11
|
+
* Emits:
|
|
12
|
+
* load - 广告加载成功
|
|
13
|
+
* close - 用户关闭广告
|
|
14
|
+
* error - 广告加载/展示失败,携带 { errCode, errMsg }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```vue
|
|
18
|
+
* <HlwAd unit-id="adunit-xxx" @load="onLoad" @error="onError" />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
defineOptions({ name: 'HlwAd' });
|
|
23
|
+
|
|
24
|
+
defineProps<{
|
|
25
|
+
/** 广告单元 ID */
|
|
26
|
+
unitId: string;
|
|
27
|
+
}>();
|
|
28
|
+
|
|
29
|
+
const emit = defineEmits<{
|
|
30
|
+
(e: 'load', event: any): void;
|
|
31
|
+
(e: 'close', event: any): void;
|
|
32
|
+
(e: 'error', event: any): void;
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
function onLoad(event: any) {
|
|
36
|
+
emit('load', event);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function onClose(event: any) {
|
|
40
|
+
emit('close', event);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function onError(event: any) {
|
|
44
|
+
console.error('[HlwAd] 广告错误:', event?.detail?.errCode, event?.detail?.errMsg);
|
|
45
|
+
emit('error', event);
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<ad
|
|
51
|
+
:unit-id="unitId"
|
|
52
|
+
@load="onLoad"
|
|
53
|
+
@close="onClose"
|
|
54
|
+
@error="onError"
|
|
55
|
+
/>
|
|
56
|
+
</template>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineComponent, ref, computed } from 'vue';
|
|
2
|
+
|
|
3
|
+
export interface AvatarProps {
|
|
4
|
+
src?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
size?: 'small' | 'medium' | 'large';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default defineComponent({
|
|
10
|
+
name: 'Avatar',
|
|
11
|
+
props: {
|
|
12
|
+
src: { type: String },
|
|
13
|
+
name: { type: String },
|
|
14
|
+
size: { type: String as () => 'small' | 'medium' | 'large', default: 'medium' },
|
|
15
|
+
},
|
|
16
|
+
setup(props) {
|
|
17
|
+
const loadError = ref(false);
|
|
18
|
+
|
|
19
|
+
const initial = computed(() => {
|
|
20
|
+
if (!props.name) return '?';
|
|
21
|
+
return props.name.charAt(0).toUpperCase();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function onError() { loadError.value = true; }
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
const sizeClass = `hlw-avatar--${props.size}`;
|
|
28
|
+
return (
|
|
29
|
+
// @ts-ignore - uni app nodes
|
|
30
|
+
h('view', { class: `hlw-avatar ${sizeClass}` }, [
|
|
31
|
+
props.src && !loadError.value
|
|
32
|
+
? (
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
h('image', {
|
|
35
|
+
class: 'hlw-avatar__image',
|
|
36
|
+
src: props.src,
|
|
37
|
+
mode: 'aspectFill',
|
|
38
|
+
onError,
|
|
39
|
+
})
|
|
40
|
+
)
|
|
41
|
+
: (
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
h('view', { class: 'hlw-avatar__placeholder' }, [
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
h('text', { class: 'hlw-avatar__initial' }, initial.value),
|
|
46
|
+
])
|
|
47
|
+
),
|
|
48
|
+
])
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineComponent, useSlots } from 'vue';
|
|
2
|
+
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: 'Empty',
|
|
5
|
+
props: {
|
|
6
|
+
text: { type: String },
|
|
7
|
+
image: { type: String },
|
|
8
|
+
},
|
|
9
|
+
setup(props) {
|
|
10
|
+
const slots = useSlots();
|
|
11
|
+
return () => {
|
|
12
|
+
return (
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
h('view', { class: 'hlw-empty' }, [
|
|
15
|
+
props.image
|
|
16
|
+
? (
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
h('image', { class: 'hlw-empty__image', src: props.image, mode: 'aspectFit' })
|
|
19
|
+
)
|
|
20
|
+
: (
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
h('view', { class: 'hlw-empty__icon' }, [
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
h('text', '📦'),
|
|
25
|
+
])
|
|
26
|
+
),
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
h('text', { class: 'hlw-empty__text' }, props.text || '暂无数据'),
|
|
29
|
+
slots.default?.(),
|
|
30
|
+
])
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineComponent } from 'vue';
|
|
2
|
+
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: 'Loading',
|
|
5
|
+
props: {
|
|
6
|
+
text: { type: String },
|
|
7
|
+
},
|
|
8
|
+
setup(props) {
|
|
9
|
+
return () => {
|
|
10
|
+
const dots = Array.from({ length: 12 }, (_, i) =>
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
h('view', { key: i + 1, class: 'hlw-loading__dot' }),
|
|
13
|
+
);
|
|
14
|
+
return (
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
h('view', { class: 'hlw-loading' }, [
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
h('view', { class: 'hlw-loading__spinner' }, dots),
|
|
19
|
+
props.text
|
|
20
|
+
? (
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
h('text', { class: 'hlw-loading__text' }, props.text)
|
|
23
|
+
)
|
|
24
|
+
: null,
|
|
25
|
+
])
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { defineComponent } from 'vue';
|
|
2
|
+
|
|
3
|
+
export interface MenuItem {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
value?: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
action?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default defineComponent({
|
|
13
|
+
name: 'MenuList',
|
|
14
|
+
props: {
|
|
15
|
+
items: { type: Array as () => MenuItem[], required: true },
|
|
16
|
+
},
|
|
17
|
+
emits: ['click'],
|
|
18
|
+
setup(props, { emit }) {
|
|
19
|
+
function onTap(item: MenuItem) {
|
|
20
|
+
if (item.url) {
|
|
21
|
+
uni.navigateTo({ url: item.url });
|
|
22
|
+
} else if (item.action) {
|
|
23
|
+
item.action();
|
|
24
|
+
}
|
|
25
|
+
emit('click', item);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
const items = props.items.map((item) =>
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
h('view', {
|
|
32
|
+
class: 'hlw-menu-list__item',
|
|
33
|
+
key: item.key,
|
|
34
|
+
onClick: () => onTap(item),
|
|
35
|
+
}, [
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
h('view', { class: 'hlw-menu-list__left' }, [
|
|
38
|
+
item.icon
|
|
39
|
+
? (
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
h('text', { class: 'hlw-menu-list__icon' }, item.icon)
|
|
42
|
+
)
|
|
43
|
+
: null,
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
h('text', { class: 'hlw-menu-list__label' }, item.label),
|
|
46
|
+
]),
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
h('view', { class: 'hlw-menu-list__right' }, [
|
|
49
|
+
item.value
|
|
50
|
+
? (
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
h('text', { class: 'hlw-menu-list__value' }, item.value)
|
|
53
|
+
)
|
|
54
|
+
: null,
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
h('text', { class: 'hlw-menu-list__arrow' }, '›'),
|
|
57
|
+
]),
|
|
58
|
+
]),
|
|
59
|
+
);
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
return h('view', { class: 'hlw-menu-list' }, items);
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hlw-uni/mp-vue — Vue 组件库统一导出
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { default as HlwAd } from './components/hlw-ad/index.vue';
|
|
6
|
+
export { default as HlwAvatar } from './components/hlw-avatar/index';
|
|
7
|
+
export { default as HlwEmpty } from './components/hlw-empty/index';
|
|
8
|
+
export { default as HlwLoading } from './components/hlw-loading/index';
|
|
9
|
+
export { default as HlwMenuList, type MenuItem } from './components/hlw-menu-list/index';
|