better-staridc-MNBT
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-plus-box-outline"></i>添加程序</h3>
6 <p class="td-page-subtitle">上传程序源码包并填写基础信息</p>
7 </div>
8 <t-button theme="default" variant="outline" @click="goBack">
9 <i class="mdi mdi-arrow-left"></i> 返回列表
10 </t-button>
11 </div>
12
13 <div class="td-set-card">
14 <div class="td-set-card-hd">
15 <div class="td-set-icon"><i class="mdi mdi-webpack"></i></div>
16 <div>
17 <h4>程序基础信息</h4>
18 <p>填写名称、空间、价格与程序源码包</p>
19 </div>
20 </div>
21 <div class="td-set-card-bd">
22 <t-loading :loading="loading" text="提交中…" size="small">
23 <div class="td-form">
24 <div class="td-form-row">
25 <label>程序名称 <span class="req">*</span></label>
26 <t-input v-model="form.cxname" placeholder="请输入程序名称" clearable />
27 </div>
28
29 <div class="td-form-row">
30 <label>程序介绍 <span class="req">*</span></label>
31 <t-textarea
32 v-model="form.cxjs"
33 :autosize="{ minRows: 3, maxRows: 8 }"
34 placeholder="请输入程序介绍"
35 />
36 </div>
37
38 <div class="td-form-row-grid">
39 <div class="td-form-row">
40 <label>价格 (元) <span class="req">*</span></label>
41 <t-input-number v-model="form.cxrmb" :min="0" theme="normal" placeholder="0 表示免费" />
42 <div class="td-form-hint">0 表示免费</div>
43 </div>
44
45 <div class="td-form-row">
46 <label>网页空间 (MB) <span class="req">*</span></label>
47 <t-input-number v-model="form.cxwebkj" :min="0" theme="normal" />
48 </div>
49
50 <div class="td-form-row">
51 <label>数据库空间 (MB) <span class="req">*</span></label>
52 <t-input-number v-model="form.cxsqlkj" :min="0" theme="normal" />
53 </div>
54 </div>
55
56 <div class="td-form-row">
57 <label>部署完成提示</label>
58 <t-textarea
59 v-model="form.alerts"
60 :autosize="{ minRows: 2, maxRows: 4 }"
61 placeholder="部署完成后给用户的提示语,可留空"
62 />
63 </div>
64
65 <div class="td-form-row">
66 <label>程序源码包 <span class="req">*</span></label>
67 <div class="file-row">
68 <label class="file-pick">
69 <i class="mdi mdi-file-upload-outline"></i>
70 <span>{{ form.filecx ? form.filecx.name : '选择文件…' }}</span>
71 <input type="file" accept=".zip,.tar,.gz,.tgz" @change="onPickFile" />
72 </label>
73 <span class="td-text-mute td-text-xs">支持 zip / tar.gz 压缩包</span>
74 </div>
75 </div>
76
77 <div class="td-form-switch">
78 <div class="td-form-switch-txt">
79 <strong>是否上架</strong>
80 <span>关闭后保存为下架状态,可在列表中再开启</span>
81 </div>
82 <t-switch v-model="form.kg" />
83 </div>
84
85 <div class="td-form-note">
86 <b>说明:</b> 本表单仅录入基础字段。如需配置安装时操作 (pz)、用户填写表单 (inp)、展示图 (src) 等高级字段,
87 请使用 default 主题或后续在程序列表中编辑。
88 </div>
89
90 <div class="td-form-actions">
91 <t-button theme="primary" :loading="loading" @click="submit">
92 <i class="mdi mdi-content-save-outline"></i> 提交添加
93 </t-button>
94 <t-button theme="default" variant="outline" @click="goBack">取消</t-button>
95 </div>
96 </div>
97 </t-loading>
98 </div>
99 </div>
100 </div>
101</template>
102
103<script setup>
104import { reactive, ref } from 'vue'
105import { useRouter } from 'vue-router'
106import { MessagePlugin } from 'tdesign-vue-next'
107import { addProgram } from '@/admin/api/program'
108
109const router = useRouter()
110
111const loading = ref(false)
112
113const form = reactive({
114 cxname: '',
115 cxjs: '',
116 cxrmb: 0,
117 cxwebkj: 0,
118 cxsqlkj: 0,
119 alerts: '',
120 filecx: null,
121 kg: true,
122})
123
124function onPickFile(e) {
125 const f = e.target.files && e.target.files[0]
126 if (f) form.filecx = f
127}
128
129function goBack() {
130 router.push('/program')
131}
132
133async function submit() {
134 if (!form.cxname) return MessagePlugin.warning('请填写程序名称')
135 if (!form.cxjs) return MessagePlugin.warning('请填写程序介绍')
136 if (form.cxrmb == null || form.cxrmb === '') return MessagePlugin.warning('请填写价格')
137 if (form.cxwebkj == null || form.cxwebkj === '') return MessagePlugin.warning('请填写网页空间')
138 if (form.cxsqlkj == null || form.cxsqlkj === '') return MessagePlugin.warning('请填写数据库空间')
139 if (!form.filecx) return MessagePlugin.warning('请选择程序源码包')
140
141 const fd = new FormData()
142 fd.append('gn', 'cxtj')
143 fd.append('cxname', form.cxname)
144 fd.append('cxjs', form.cxjs)
145 fd.append('cxrmb', String(form.cxrmb))
146 fd.append('cxwebkj', String(form.cxwebkj))
147 fd.append('cxsqlkj', String(form.cxsqlkj))
148 fd.append('alerts', form.alerts || '')
149 fd.append('filecx', form.filecx)
150 fd.append('kg', form.kg ? 'true' : 'false')
151
152 loading.value = true
153 const r = await addProgram(fd)
154 loading.value = false
155 if (r.ok) {
156 MessagePlugin.success('添加成功')
157 router.push('/program')
158 }
159}
160</script>
161
162<style scoped>
163.req {
164 color: var(--td-error);
165 margin-left: 2px;
166}
167.td-form-row-grid {
168 display: grid;
169 grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
170 gap: 16px;
171}
172.file-row {
173 display: flex;
174 align-items: center;
175 gap: 12px;
176 flex-wrap: wrap;
177}
178.file-pick {
179 display: inline-flex;
180 align-items: center;
181 gap: 6px;
182 padding: 7px 14px;
183 background: var(--td-surface);
184 border: 1px dashed var(--td-border);
185 border-radius: var(--td-radius);
186 cursor: pointer;
187 font-size: 13px;
188 color: var(--td-text-secondary);
189 transition: border-color 0.15s ease, color 0.15s ease;
190}
191.file-pick:hover {
192 border-color: var(--td-brand);
193 color: var(--td-brand);
194}
195.file-pick input[type='file'] {
196 position: absolute;
197 width: 0;
198 height: 0;
199 opacity: 0;
200 overflow: hidden;
201}
202</style>