feima-shortcuts 0.1.0 → 0.1.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/bin/feima.js
CHANGED
|
@@ -28,7 +28,7 @@ const run = () => {
|
|
|
28
28
|
type: "list",
|
|
29
29
|
name: "template-type",
|
|
30
30
|
message: "请选择页面模版类型",
|
|
31
|
-
choices: ["card", 'tabs', 'form'],
|
|
31
|
+
choices: ["card", 'tabs', 'form-card','form-collapse(没有拆分组件)'],
|
|
32
32
|
when: function (answers) {
|
|
33
33
|
return answers['template-path'];
|
|
34
34
|
},
|
package/package.json
CHANGED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const { makeDir } = require("../../utils/makeDir");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function toKebabCase(str) {
|
|
6
|
+
if (/^[A-Z]/.test(str)) {
|
|
7
|
+
throw new Error('首字母不能是大写');
|
|
8
|
+
}
|
|
9
|
+
return str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const templateStr = ({fileName}) => {
|
|
13
|
+
const className = toKebabCase(fileName);
|
|
14
|
+
|
|
15
|
+
return `<template>
|
|
16
|
+
<div class="${className}">
|
|
17
|
+
<el-form
|
|
18
|
+
ref="formRef"
|
|
19
|
+
inline
|
|
20
|
+
:model="formValue"
|
|
21
|
+
label-width="120px"
|
|
22
|
+
label-suffix=":"
|
|
23
|
+
>
|
|
24
|
+
<el-collapse v-model="openNames">
|
|
25
|
+
<el-collapse-item name="base">
|
|
26
|
+
<template #title>
|
|
27
|
+
<div class="${className}-header">基本信息(collapse-item内的el-form-item应该拆分到组件内)</div>
|
|
28
|
+
</template>
|
|
29
|
+
<el-form-item
|
|
30
|
+
class="block"
|
|
31
|
+
label="测试姓名"
|
|
32
|
+
prop="name"
|
|
33
|
+
:rules="[
|
|
34
|
+
{
|
|
35
|
+
required: true,
|
|
36
|
+
message: '请输入测试姓名',
|
|
37
|
+
trigger: 'blur',
|
|
38
|
+
},
|
|
39
|
+
]"
|
|
40
|
+
>
|
|
41
|
+
<el-input v-model="formValue.name" />
|
|
42
|
+
</el-form-item>
|
|
43
|
+
<el-form-item
|
|
44
|
+
label="测试2"
|
|
45
|
+
prop="test2"
|
|
46
|
+
>
|
|
47
|
+
<el-input v-model="formValue.test1" />
|
|
48
|
+
</el-form-item>
|
|
49
|
+
<el-form-item
|
|
50
|
+
label="测试3"
|
|
51
|
+
prop="test3"
|
|
52
|
+
>
|
|
53
|
+
<el-input v-model="formValue.test1" />
|
|
54
|
+
</el-form-item>
|
|
55
|
+
</el-collapse-item>
|
|
56
|
+
<el-collapse-item name="other">
|
|
57
|
+
<template #title>
|
|
58
|
+
<div class="${className}-header">其他信息</div>
|
|
59
|
+
</template>
|
|
60
|
+
<el-form-item
|
|
61
|
+
class="block-content"
|
|
62
|
+
label="备注(只是示例)"
|
|
63
|
+
prop="remark"
|
|
64
|
+
>
|
|
65
|
+
<el-input
|
|
66
|
+
v-model="formValue.remark"
|
|
67
|
+
:rows="3"
|
|
68
|
+
type="textarea"
|
|
69
|
+
/>
|
|
70
|
+
</el-form-item>
|
|
71
|
+
<el-form-item
|
|
72
|
+
class="block-content"
|
|
73
|
+
label="富文本(只是示例)"
|
|
74
|
+
prop="remark"
|
|
75
|
+
>
|
|
76
|
+
<ProFormTinymce v-model="formValue.richText" />
|
|
77
|
+
</el-form-item>
|
|
78
|
+
|
|
79
|
+
<el-form-item
|
|
80
|
+
class="block-content"
|
|
81
|
+
label="富文本(只是示例)"
|
|
82
|
+
prop="remark"
|
|
83
|
+
>
|
|
84
|
+
<ProFormImage
|
|
85
|
+
v-model="formValue.images"
|
|
86
|
+
:limit="1"
|
|
87
|
+
:before-upload="handleBeforeUpload"
|
|
88
|
+
>
|
|
89
|
+
<template #footer>
|
|
90
|
+
<div class="pro-form-image-tip">
|
|
91
|
+
<el-icon color="red"><Warning /></el-icon>
|
|
92
|
+
仅支持上传宽度750px且大小不超过1MB图片
|
|
93
|
+
</div>
|
|
94
|
+
</template>
|
|
95
|
+
</ProFormImage>
|
|
96
|
+
</el-form-item>
|
|
97
|
+
</el-collapse-item>
|
|
98
|
+
</el-collapse>
|
|
99
|
+
</el-form>
|
|
100
|
+
|
|
101
|
+
<PageFooter>
|
|
102
|
+
<el-button
|
|
103
|
+
type="primary"
|
|
104
|
+
v-fLoading="onSubmit"
|
|
105
|
+
>
|
|
106
|
+
提交
|
|
107
|
+
</el-button>
|
|
108
|
+
</PageFooter>
|
|
109
|
+
</div>
|
|
110
|
+
</template>
|
|
111
|
+
|
|
112
|
+
<script setup lang="ts">
|
|
113
|
+
import { ref } from "vue";
|
|
114
|
+
import { ElMessage } from "element-plus";
|
|
115
|
+
|
|
116
|
+
import PageFooter from "@/components/PageFooter.vue";
|
|
117
|
+
import ProFormTinymce from "@/components/ProFormTinymce.vue";
|
|
118
|
+
import ProFormImage from "@/components/ProFormImage.vue";
|
|
119
|
+
|
|
120
|
+
defineOptions({
|
|
121
|
+
name: "${fileName}",
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const formRef = ref<any>();
|
|
125
|
+
const formValue = ref<any>({
|
|
126
|
+
name: "",
|
|
127
|
+
test2: "",
|
|
128
|
+
test3: "",
|
|
129
|
+
remark: "",
|
|
130
|
+
richText: "",
|
|
131
|
+
images: [],
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const openNames = ref(["base", "other"]);
|
|
135
|
+
|
|
136
|
+
// 上传之前的处理
|
|
137
|
+
const handleBeforeUpload = (file: any) => {
|
|
138
|
+
if (file.size > 1048576) {
|
|
139
|
+
ElMessage.error("超出最大上传大小,图片不能大于1MB");
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
// 示例,不需要自己删除
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
const reader = new FileReader();
|
|
145
|
+
|
|
146
|
+
reader.onload = () => {
|
|
147
|
+
const img: any = new Image();
|
|
148
|
+
img.src = reader.result;
|
|
149
|
+
|
|
150
|
+
img.onload = () => {
|
|
151
|
+
// 检查图片宽度是否超过 750px
|
|
152
|
+
if (img.width != 750) {
|
|
153
|
+
ElMessage.error("图片宽度需为 750 像素");
|
|
154
|
+
reject(); // 取消上传
|
|
155
|
+
} else {
|
|
156
|
+
resolve(""); // 宽度合格,允许上传
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
img.onerror = () => {
|
|
161
|
+
ElMessage.error("图片加载失败");
|
|
162
|
+
reject(); // 图片加载失败,取消上传
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
reader.readAsDataURL(file); // 读取文件
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const onSubmit = async () => {
|
|
170
|
+
await formRef.value.validate();
|
|
171
|
+
try {
|
|
172
|
+
const { images, ...values } = formValue.value;
|
|
173
|
+
const submitData = {
|
|
174
|
+
...values,
|
|
175
|
+
images: images.map((item: any) => item.path).join(","),
|
|
176
|
+
};
|
|
177
|
+
let formData = new FormData();
|
|
178
|
+
formData.append("json", JSON.stringify(submitData));
|
|
179
|
+
// const res: any = await addTransferOrder({
|
|
180
|
+
// data: formData,
|
|
181
|
+
// });
|
|
182
|
+
// if (res.code != 200) {
|
|
183
|
+
// ElMessage.error(res.message || "系统出错");
|
|
184
|
+
// return;
|
|
185
|
+
// }
|
|
186
|
+
// ElMessage.success(res.message);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error(error);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
</script>
|
|
192
|
+
<style lang="scss" scoped>
|
|
193
|
+
.${className} {
|
|
194
|
+
padding-bottom: var(--page-footer-height);
|
|
195
|
+
--form-item-content: 250px;
|
|
196
|
+
|
|
197
|
+
:deep(.el-collapse) {
|
|
198
|
+
border-top: none;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
:deep(.el-form-item) {
|
|
202
|
+
vertical-align: top;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
:deep(.el-form-item__content) {
|
|
206
|
+
width: var(--form-item-content);
|
|
207
|
+
flex: 0 auto;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.block {
|
|
211
|
+
width: 100%;
|
|
212
|
+
}
|
|
213
|
+
.block-content {
|
|
214
|
+
width: 100%;
|
|
215
|
+
|
|
216
|
+
:deep(.el-form-item__content) {
|
|
217
|
+
width: 100%;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&-header {
|
|
222
|
+
margin-left: var(--base-padding);
|
|
223
|
+
position: relative;
|
|
224
|
+
font-size: var(--base-title-h3);
|
|
225
|
+
font-weight: bold;
|
|
226
|
+
line-height: 1.34;
|
|
227
|
+
padding-left: var(--base-padding);
|
|
228
|
+
|
|
229
|
+
&::after {
|
|
230
|
+
content: "\\0020";
|
|
231
|
+
position: absolute;
|
|
232
|
+
left: 0;
|
|
233
|
+
top: 50%;
|
|
234
|
+
width: 4px;
|
|
235
|
+
height: 70%;
|
|
236
|
+
transform: translateY(-50%);
|
|
237
|
+
background-color: var(--el-text-color-primary);
|
|
238
|
+
border-radius: 4px;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.el-collapse-item {
|
|
243
|
+
margin-bottom: var(--el-main-padding);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
</style>`;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
exports.run = function (answers) {
|
|
252
|
+
const filePath = `./src/views/${answers['template-path']}.vue`;
|
|
253
|
+
const parts = filePath.split('/');
|
|
254
|
+
const fileName = parts[parts.length - 2];
|
|
255
|
+
const fileIndex = parts[parts.length - 1];
|
|
256
|
+
const makeDirPath = [...parts].slice(0, -1).join('/');
|
|
257
|
+
|
|
258
|
+
makeDir(makeDirPath);
|
|
259
|
+
process.chdir(makeDirPath);
|
|
260
|
+
|
|
261
|
+
const template = templateStr({ fileName });
|
|
262
|
+
|
|
263
|
+
const targetFilePath = `./${fileIndex}`;
|
|
264
|
+
|
|
265
|
+
// 新增:判断文件是否存在
|
|
266
|
+
if (fs.existsSync(targetFilePath)) {
|
|
267
|
+
console.log(`❌ 文件已存在:${targetFilePath},未进行覆盖操作。`);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fs.writeFileSync(targetFilePath, template);
|
|
272
|
+
console.log(`✅ 文件创建成功`);
|
|
273
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const card = require("./card");
|
|
2
2
|
const tabs = require("./tabs");
|
|
3
|
-
const
|
|
3
|
+
const formCard = require("./formCard");
|
|
4
|
+
const formCollapse = require("./formCollapse");
|
|
4
5
|
|
|
5
6
|
exports.run = function (answers) {
|
|
6
7
|
if (answers['template-type'] === "card") {
|
|
@@ -9,7 +10,10 @@ exports.run = function (answers) {
|
|
|
9
10
|
if (answers['template-type'] === "tabs") {
|
|
10
11
|
tabs.run(answers);
|
|
11
12
|
};
|
|
12
|
-
if (answers['template-type'] === "form") {
|
|
13
|
-
|
|
13
|
+
if (answers['template-type'] === "form-card") {
|
|
14
|
+
formCard.run(answers);
|
|
15
|
+
};
|
|
16
|
+
if (answers['template-type'] === "form-collapse(没有拆分组件)") {
|
|
17
|
+
formCollapse.run(answers);
|
|
14
18
|
};
|
|
15
19
|
};
|
|
File without changes
|