@neatui/nuxt 1.1.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neatui/nuxt",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "NeatUI component library for Nuxt 3",
5
5
  "main": "./src/index.ts",
6
6
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  <!-- 实验性插件 -->
2
2
  <template>
3
- <Teleport to="area">
3
+ <Teleport :to="area">
4
4
  <div
5
5
  v-if="state.view"
6
6
  :am-view="am"
@@ -1,5 +1,4 @@
1
1
  import Pagination from './Pagination@a.vue';
2
2
  import MoreTools from './MoreTools.vue';
3
3
  import FormDraftsView from './FormDraftsView.vue';
4
- import FormVerifyView from './FormVerifyView.vue';
5
- export { Pagination, MoreTools, FormDraftsView, FormVerifyView };
4
+ export { Pagination, MoreTools, FormDraftsView };
@@ -1,207 +0,0 @@
1
- <template>
2
- <div ui-tips="@a co:well">
3
- <button :ui-btn="`@a s none ${verify?.length ? '' : ':square'}`" :class="`${verify?.length ? 'co-risk' : 'co-well'}`" @click="state.show = state.show ? 0 : 1">
4
- <i v-if="verify?.length" class="icon icon-verify-no co-risk"></i>
5
- <i v-else class="icon icon-verify-ok co-well"></i>
6
- <span v-if="verify?.length">{{ verify?.length }}</span>
7
- </button>
8
- <div ui-tips-box="tl" :ux-view="state.show" class="w-xl mob:w-ll n-ms">
9
- <div class="fekit-layer-close" ui-flex="row cm" @click="state.show = 0"><i class="icon icon-close fs-xs"></i></div>
10
- <h4>温馨提示</h4>
11
- <p v-if="verify?.length" class="ny-sm">本条记录疑似有{{ verify?.length }}个错误,您再检查一遍吧~</p>
12
- <p v-else class="nb-sm">好棒哦,没有发现任何错误!</p>
13
- <p v-if="verify.length">
14
- <span v-if="state.detail" class="ux-click co-link" @click="state.detail = 0">隐藏详情<i class="icon icon-dropdown r180"></i></span>
15
- <span v-else class="ux-click co-link" @click="state.detail = 1">显示详情<i class="icon icon-dropdown"></i></span>
16
- </p>
17
- <ul v-if="state.detail" class="co-read" ui-scroll=":y s" style="max-height: 8em">
18
- <li v-for="(err, idx) in verify" :key="idx">
19
- <i v-if="err.type === 'warn'" class="icon icon-warn co-warn"></i>
20
- <i v-else class="icon icon-error co-risk"></i>
21
- <span class="nl-ss">
22
- <span class="ux-hover ny-xs nx-ss r-sm" @click="fScrollToField(err.path)">[{{ err.label }}]</span>
23
- <span class="ml-sm">{{ err.msg || '有一个错误' }}</span>
24
- </span>
25
- </li>
26
- </ul>
27
- </div>
28
- </div>
29
- </template>
30
- <script setup lang="ts">
31
- import { computed, reactive, toRefs, watch, onMounted, ref, onUnmounted } from 'vue';
32
- import { useRoute } from 'vue-router';
33
- import scrollTo from '@fekit/scrollto';
34
- import { deepcopy, isArray, isObject, isFunction } from '@fekit/utils';
35
-
36
- const route: any = useRoute();
37
-
38
- const props: any = defineProps({
39
- area: {
40
- type: [Object, HTMLElement],
41
- default: () => (import.meta.client ? document.body : null),
42
- },
43
- data: {
44
- type: Object,
45
- required: true,
46
- default: () => ({}),
47
- },
48
- form: {
49
- type: Object,
50
- default: () => ({}),
51
- },
52
- });
53
-
54
- const state: any = reactive({
55
- __update: true,
56
- mode: route.query.mode,
57
- show: 0,
58
- detail: 1,
59
- // 数据校验
60
- verify: computed(() => {
61
- const error: any = [{ __update: state.__update }];
62
- const edit = props.data || {};
63
- const form = props.form || {};
64
- // 核心
65
- const core = (data: any = {}, form: any = {}, path: any = '') => {
66
- Object.keys(data).forEach((item: any) => {
67
- // 是否有表单结构
68
- if (form[item]) {
69
- // 是否末端
70
- if (form[item]?.child && (isArray(data[item]) || isObject(data[item]))) {
71
- if (isArray(data[item])) {
72
- data[item].forEach((sub: any, idx: number) => {
73
- core(sub, form[item].child, path + '-' + form[item].field + '-' + idx);
74
- });
75
- } else {
76
- (Object.values(data[item]) || []).forEach((sub: any, idx: number) => {
77
- core(sub, form[item].child, path + '-' + form[item].field + '-' + idx);
78
- });
79
- }
80
- } else {
81
- const value = data[item];
82
- const { label = '', field = '', rules = [], clear = false } = form[item] || {};
83
- if (isFunction(clear) ? !clear(data) : !clear) {
84
- const _path = path + '-' + field;
85
- rules?.forEach((rule: any = {}) => {
86
- const { type = '', msg = '', required = null, validator = null } = rule;
87
- if (required) {
88
- if (isArray(value)) {
89
- if (!value.length) {
90
- error.push({ field, label, type, msg, path: _path });
91
- }
92
- } else {
93
- if (!value) {
94
- error.push({ field, label, type, msg, path: _path });
95
- }
96
- }
97
- }
98
- const _validator = isFunction(validator) ? validator(deepcopy(props.data)) : null;
99
- if (value && _validator && !_validator(value)) {
100
- error.push({ field, label, type, msg, path: _path });
101
- }
102
- });
103
- }
104
- }
105
- }
106
- });
107
- };
108
- core(edit, form, '#form-field');
109
- error.shift();
110
- return error;
111
- }),
112
- });
113
- const { verify = [] }: any = toRefs(state);
114
-
115
- // 为了在退出编辑的时候平滑过滤
116
- watch(
117
- () => route.query.mode,
118
- (mode) => {
119
- if (mode) {
120
- state.mode = mode;
121
- } else {
122
- setTimeout(() => {
123
- state.mode = '';
124
- state.show = 0;
125
- }, 300);
126
- }
127
- },
128
- );
129
-
130
- const fScrollToField = (path: any) => {
131
- if (!import.meta.client) return;
132
- const dom = document.querySelector(path);
133
- if (dom) {
134
- scrollTo({
135
- el: props.area,
136
- to: {
137
- y: dom,
138
- },
139
- offset: { y: -36 },
140
- then() {
141
- const input = dom.querySelector('input');
142
- if (input) {
143
- input?.focus();
144
- }
145
- },
146
- });
147
- }
148
- };
149
-
150
- // 初始化时进入页面时自动弹出
151
- const timer1: any = ref(null);
152
- onMounted(() => {
153
- timer1.value = setTimeout(() => {
154
- if (state.verify.length) {
155
- state.show = 1;
156
- }
157
- }, 1000);
158
- });
159
- onUnmounted(() => {
160
- clearTimeout(timer1.value);
161
- });
162
-
163
- const timer2: any = ref(null);
164
- watch(
165
- () => state.verify,
166
- () => {
167
- clearTimeout(timer2.value);
168
- if (state.show && !state.verify.length) {
169
- timer2.value = setTimeout(() => {
170
- state.show = 0;
171
- }, 1000);
172
- }
173
- },
174
- );
175
-
176
- // 初始化后进入页面时自动弹出
177
- const timer3: any = ref(null);
178
- watch(
179
- () => route.query.mode,
180
- (mode: any) => {
181
- clearTimeout(timer3.value);
182
- if (mode === 'edit') {
183
- timer3.value = setTimeout(() => {
184
- if (state.verify.length) {
185
- state.show = 1;
186
- }
187
- }, 1000);
188
- } else {
189
- if (state.show) {
190
- setTimeout(() => {
191
- state.show = 0;
192
- }, 300);
193
- }
194
- }
195
- },
196
- );
197
-
198
- watch(
199
- () => props.data,
200
- () => {
201
- state.__update = !state.__update;
202
- },
203
- {
204
- deep: true,
205
- },
206
- );
207
- </script>