无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<template>
    <basic-container>
 
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model:page="page" ref="crud"
            @row-del="rowDel" v-model="form" :permission="permissionList" @row-update="rowUpdate" @row-save="rowSave"
            :before-open="beforeOpen" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad">
 
            <!-- 自定义证书地址列 -->
            <template #url="scope">
                <el-link :href="scope.row.url" target="_blank" type="primary">
                    下载密钥
                </el-link>
            </template>
 
            <!-- 自定义过期时间列 -->
            <template #expireDay="scope">
                <span :style="{ color: isExpired(scope.row.expireDay) ? 'red' : 'inherit' }">
                    {{ formatExpireDay(scope.row.expireDay, scope.row.licenseType) }}
                </span>
            </template>
 
            <!-- 自定义设备数量列 -->
            <template #printClientCount="scope">
                <span>
                    {{ scope.row.printClientCount === -1 ? '不限制' : scope.row.printClientCount }}
                </span>
            </template>
 
            <!-- 自定义是否校验机器码列 -->
            <template #checkMachineCode="scope">
                <span>
                    {{ scope.row.checkMachineCode ? '校验机器码' : '不校验' }}
                </span>
            </template>
            <template #menu-left>
                <el-button type="primary" icon="el-icon-plus" @click="createLicenseShow()">新 增
                </el-button>
            </template>
        </avue-crud>
 
        <!-- 新增弹窗 -->
        <el-dialog title="新增 License" v-model="addDialogVisible" width="70%" :close-on-click-modal="false"
            @close="resetForm">
            <el-form :model="newLicense" ref="licenseForm" label-width="120px">
                <el-form-item label="机构ID" prop="licenseId">
                    <el-input v-model="newLicense.licenseId" />
                </el-form-item>
                <el-form-item label="机构名称" prop="licenseName" required>
                    <el-input v-model="newLicense.licenseName" />
                </el-form-item>
                <el-form-item label="是否验证过期时间类型" prop="licenseType" required>
                    <el-select v-model="newLicense.licenseType" placeholder="请选择">
                        <el-option label="不验证过期时间" :value="1" />
                        <el-option label="验证过期时间" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item v-if="newLicense.licenseType == 2" label="过期时间" prop="expireDay">
                    <el-date-picker v-model="newLicense.expireDay" type="date" placeholder="选择日期" />
                </el-form-item>
                <el-form-item label="设备数量" prop="printClientCount">
                    <el-radio-group v-model="deviceLimit">
                        <el-radio :label="-1">不限制</el-radio>
                        <el-radio :label="1">限制</el-radio>
                    </el-radio-group>
                    <el-input-number v-if="deviceLimit === 1" v-model="newLicense.printClientCount" :min="0"
                        placeholder="请输入数量" style="margin-top: 10px;" />
                </el-form-item>
                <el-form-item label="是否校验机器码" prop="checkMachineCode">
                    <el-switch v-model="newLicense.checkMachineCode" />
                </el-form-item>
                <el-form-item label="机器码" prop="machineCode">
                    <el-input v-model="newLicense.machineCode" type="textarea" rows="3" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="newLicense.remark" />
                </el-form-item>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="addDialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="createLicense">保存</el-button>
                </div>
            </template>
 
        </el-dialog>
    </basic-container>
</template>
 
<script>
import { getList, add } from '@/api/license/license'
import { mapGetters } from 'vuex'
 
export default {
    data () {
        return {
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            selectionList: [],
            addDialogVisible: false,
            deviceLimit: -1, // 控制设备数量选择
            newLicense: {
                licenseId: '',
                licenseName: '',
                licenseType: null,
                expireDay: null,
                printClientCount: -1,
                checkMachineCode: false,
                machineCode: '',
                remark: '',
            },
            option: {
                menuWidth: 300,
                lazy: true,
                tree: false,
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
                border: true,
                index: true,
                viewBtn: true,
                selection: false,
                excelBtn: false,
                addBtnText: '新建license',
                addBtn: true,
                dialogClickModal: false,
                grid: false,
 
                height: 'auto',
                calcHeight: 20,
 
                column: [
                    {
                        label: '机构ID',
                        prop: 'licenseId',
                        labelWidth: 130,
                        search: false,
                        rules: [
                            {
                                required: false,
                                message: '请输入机构ID',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '机构名称',
                        prop: 'licenseName',
                        labelWidth: 130,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入机构名称',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '是否验证过期时间',
                        prop: 'licenseType',
                        type: 'select',
                        labelWidth: 130,
                        dicData: [
                            {
                                label: '不验证过期时间',
                                value: 1,
                            },
                            {
                                label: '验证过期时间',
                                value: 2,
                            },
                        ],
                        rules: [
                            {
                                required: true,
                                message: '请选择类型',
                                trigger: 'change',
                            },
                        ],
                    },
                    {
                        label: '过期时间',
                        prop: 'expireDay',
                        type: 'date',
                        labelWidth: 130,
                        slot: true, // 启用自定义插槽
                        rules: [
                            {
                                required: false,
                                message: '请选择过期时间',
                                trigger: 'change',
                            },
                        ],
                    },
                    {
                        label: '设备数量',
                        prop: 'printClientCount',
                        type: 'number',
                        labelWidth: 130,
                        slot: true, // 启用自定义插槽
                        rules: [
                            {
                                required: false,
                                message: '请输入设备数量',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '是否校验机器码',
                        prop: 'checkMachineCode',
                        type: 'switch',
                        labelWidth: 130,
                        slot: true, // 启用自定义插槽
                        rules: [
                            {
                                required: false,
                                message: '请选择是否校验机器码',
                                trigger: 'change',
                            },
                        ],
                    },
                    {
                        label: '机器码',
                        prop: 'machineCode',
                        type: 'textarea',
                        labelWidth: 130,
                        rules: [
                            {
                                required: false,
                                message: '请输入机器码',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '密钥地址',
                        prop: 'url',
                        labelWidth: 130,
                        slot: true, // 启用自定义插槽
                        rules: [
                            {
                                required: false,
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '备注',
                        prop: 'remark',
                        labelWidth: 130,
                        rules: [
                            {
                                required: false,
                                message: '请输入备注',
                                trigger: 'blur',
                            },
                        ],
                    },
                ],
            },
            data: [],
        }
    },
    computed: {
        ...mapGetters(['userInfo', 'permission']),
        permissionList () {
            return {
                addBtn: this.validData(this.permission.license_add, false),
                viewBtn: this.validData(this.permission.license_view, true),
                delBtn: this.validData(this.permission.license_delete, false),
                editBtn: this.validData(this.permission.license_edit, false),
            }
        },
    },
    methods: {
        isExpired (expireDay) {
            const now = new Date()
            return new Date(expireDay) < now
        },
        formatExpireDay (expireDay, licenseType) {
            if (licenseType == 2 && this.isExpired(expireDay)) {
                return `${expireDay} (已过期)`
            }
            if (licenseType == 1) {
                return `永久`
            }
            return expireDay
        },
        rowSave (row, done, loading) {
            add(row).then(
                () => {
                    this.onLoad(this.page)
                    this.$message({
                        type: 'success',
                        message: '操作成功!',
                    })
                    done()
                },
                error => {
                    console.error(error)
                    loading()
                }
            )
        },
        createLicenseShow () {
            this.addDialogVisible = true
        },
        createLicense () {
            // 格式化过期时间
            if (this.newLicense.expireDay) {
                this.newLicense.expireDay = this.formatDate(this.newLicense.expireDay)
                console.log(this.newLicense.expireDay)
 
            }
 
            // 保存数据
            add(this.newLicense).then(() => {
                this.$message.success('新增成功')
                this.addDialogVisible = false
                this.onLoad(this.page)
            }).catch(error => {
                console.error(error)
                this.$message.error('新增失败')
            })
        },
        formatDate (date) {
            const d = new Date(date)
            const year = d.getFullYear()
            const month = String(d.getMonth() + 1).padStart(2, '0')
            const day = String(d.getDate()).padStart(2, '0')
            return `${year}-${month}-${day}`
        },
        onLoad (page, params = {}) {
            this.loading = true
            getList(page.currentPage, page.pageSize, params).then(res => {
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.loading = false
            })
        },
    },
}
</script>
 
<style lang="scss" scoped></style>