添加博客标签
This commit is contained in:
parent
e6c72d7a3d
commit
ecbb304fa6
@ -46,6 +46,7 @@
|
||||
"jsencrypt": "3.3.1",
|
||||
"nprogress": "0.2.0",
|
||||
"pinia": "^2.1.7",
|
||||
"pinyin-pro": "^3.24.2",
|
||||
"vue": "^3.3.8",
|
||||
"vue-cropper": "1.0.3",
|
||||
"vue-i18n": "9.2.2",
|
||||
|
44
src/api/blog/tags.js
Normal file
44
src/api/blog/tags.js
Normal file
@ -0,0 +1,44 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询博客标签列表
|
||||
export function listTags(query) {
|
||||
return request({
|
||||
url: '/blog/tags/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询博客标签详细
|
||||
export function getTags(id) {
|
||||
return request({
|
||||
url: '/blog/tags/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增博客标签
|
||||
export function addTags(data) {
|
||||
return request({
|
||||
url: '/blog/tags',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改博客标签
|
||||
export function updateTags(data) {
|
||||
return request({
|
||||
url: '/blog/tags',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除博客标签
|
||||
export function delTags(id) {
|
||||
return request({
|
||||
url: '/blog/tags/' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
@ -69,13 +69,10 @@
|
||||
|
||||
<!-- 添加或修改博客分类对话框 -->
|
||||
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
||||
<el-form ref="categoriesRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form ref="categoriesRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input v-model="form.description" placeholder="请输入描述" />
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="父ID" prop="parentId">
|
||||
<el-tree-select
|
||||
v-model="form.parentId"
|
||||
@ -86,15 +83,18 @@
|
||||
check-strictly
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" @input="changeName" />
|
||||
</el-form-item>
|
||||
<el-form-item label="固定链接地址" prop="slug">
|
||||
<el-input v-model="form.slug" placeholder="请输入固定链接地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input v-model="form.password" placeholder="请输入密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="优先级" prop="priority">
|
||||
<el-input v-model="form.priority" placeholder="请输入优先级" />
|
||||
</el-form-item>
|
||||
<el-form-item label="固定链接地址" prop="slug">
|
||||
<el-input v-model="form.slug" placeholder="请输入固定链接地址" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
@ -108,6 +108,7 @@
|
||||
|
||||
<script setup name="Categories">
|
||||
import { listCategories, getCategories, delCategories, addCategories, updateCategories } from "@/api/blog/categories";
|
||||
import {pinyin} from "pinyin-pro";
|
||||
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
@ -274,5 +275,10 @@ function handleExport() {
|
||||
}, `categories_${new Date().getTime()}.xlsx`)
|
||||
}
|
||||
|
||||
/** 获取名称拼音做为固定链接地址 */
|
||||
function changeName() {
|
||||
form.value.slug = pinyin(form.value.name, { toneType: 'none',nonZh: 'consecutive', separator: '-' });
|
||||
}
|
||||
|
||||
getList();
|
||||
</script>
|
||||
|
304
src/views/blog/tags/index.vue
Normal file
304
src/views/blog/tags/index.vue
Normal file
@ -0,0 +1,304 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入名称"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="Plus"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['blog:tags:add']"
|
||||
>新增
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
icon="Edit"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
v-hasPermi="['blog:tags:edit']"
|
||||
>修改
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="Delete"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['blog:tags:remove']"
|
||||
>删除
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="Download"
|
||||
@click="handleExport"
|
||||
v-hasPermi="['blog:tags:export']"
|
||||
>导出
|
||||
</el-button>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="tagsList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center"/>
|
||||
<el-table-column type="index" label="序号" align="center" width="50"/>
|
||||
<el-table-column label="名称" align="center" prop="name"/>
|
||||
<el-table-column label="固定链接地址" align="center" prop="slug"/>
|
||||
<el-table-column label="背景色" align="center" prop="color">
|
||||
<template #default="scope">
|
||||
<div class="color-dot">
|
||||
<div class="dot" :style="{
|
||||
backgroundColor: scope.row.color
|
||||
}"></div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['blog:tags:edit']">
|
||||
修改
|
||||
</el-button>
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
|
||||
v-hasPermi="['blog:tags:remove']">删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改博客标签对话框 -->
|
||||
<el-dialog :title="title" v-model="open" width="780px" append-to-body>
|
||||
<el-form ref="tagsRef" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="颜色" prop="color">
|
||||
<el-input v-model="form.color" placeholder="请选择颜色">
|
||||
<template #append>
|
||||
<el-color-picker v-model="form.color" style="width: 100%"/>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" @input="changeName"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="固定链接地址" prop="slug">
|
||||
<el-input v-model="form.slug" placeholder="请输入固定链接地址"/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Tags">
|
||||
import {listTags, getTags, delTags, addTags, updateTags} from "@/api/blog/tags";
|
||||
import {pinyin} from 'pinyin-pro';
|
||||
|
||||
const {proxy} = getCurrentInstance();
|
||||
|
||||
// 表格数据
|
||||
const tagsList = ref([]);
|
||||
// 是否显示弹出层
|
||||
const open = ref(false);
|
||||
// 遮罩层
|
||||
const loading = ref(true);
|
||||
// 显示搜索条件
|
||||
const showSearch = ref(true);
|
||||
// 选中数组
|
||||
const ids = ref([]);
|
||||
// 非单个禁用
|
||||
const single = ref(true);
|
||||
// 非多个禁用
|
||||
const multiple = ref(true);
|
||||
// 总条数
|
||||
const total = ref(0);
|
||||
// 弹出层标题
|
||||
const title = ref("");
|
||||
|
||||
const data = reactive({
|
||||
form: {},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
rules: {
|
||||
id: [
|
||||
{required: true, message: "不能为空", trigger: "blur"}
|
||||
],
|
||||
name: [
|
||||
{required: true, message: "名称不能为空", trigger: "blur"}
|
||||
],
|
||||
slug: [
|
||||
{required: true, message: "固定链接地址不能为空", trigger: "blur"}
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
const {queryParams, form, rules} = toRefs(data);
|
||||
|
||||
/** 查询博客标签列表 */
|
||||
function getList() {
|
||||
loading.value = true;
|
||||
listTags(queryParams.value).then(response => {
|
||||
tagsList.value = response.rows;
|
||||
total.value = response.total;
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
// 取消按钮
|
||||
function cancel() {
|
||||
open.value = false;
|
||||
reset();
|
||||
}
|
||||
|
||||
// 表单重置
|
||||
function reset() {
|
||||
form.value = {
|
||||
id: null,
|
||||
color: '#FFFFFF',
|
||||
name: null,
|
||||
slug: null,
|
||||
createBy: null,
|
||||
createTime: null,
|
||||
updateBy: null,
|
||||
updateTime: null
|
||||
};
|
||||
proxy.resetForm("tagsRef");
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery() {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function resetQuery() {
|
||||
proxy.resetForm("queryRef");
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
// 多选框选中数据
|
||||
function handleSelectionChange(selection) {
|
||||
ids.value = selection.map(item => item.id);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
}
|
||||
|
||||
/** 新增按钮操作 */
|
||||
function handleAdd() {
|
||||
reset();
|
||||
open.value = true;
|
||||
title.value = "添加博客标签";
|
||||
}
|
||||
|
||||
/** 修改按钮操作 */
|
||||
function handleUpdate(row) {
|
||||
reset();
|
||||
const _id = row.id || ids.value
|
||||
getTags(_id).then(response => {
|
||||
form.value = response.data;
|
||||
open.value = true;
|
||||
title.value = "修改博客标签";
|
||||
});
|
||||
}
|
||||
|
||||
/** 提交按钮 */
|
||||
function submitForm() {
|
||||
proxy.$refs["tagsRef"].validate(valid => {
|
||||
if (valid) {
|
||||
|
||||
if (form.value.id != null) {
|
||||
updateTags(form.value).then(response => {
|
||||
proxy.$modal.msgSuccess("修改成功");
|
||||
open.value = false;
|
||||
getList();
|
||||
});
|
||||
} else {
|
||||
addTags(form.value).then(response => {
|
||||
proxy.$modal.msgSuccess("新增成功");
|
||||
open.value = false;
|
||||
getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
function handleDelete(row) {
|
||||
const _ids = row.id || ids.value;
|
||||
proxy.$modal.confirm('是否确认删除博客标签编号为"' + _ids + '"的数据项?').then(function () {
|
||||
return delTags(_ids);
|
||||
}).then(() => {
|
||||
getList();
|
||||
proxy.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
function handleExport() {
|
||||
proxy.download('blog/tags/export', {
|
||||
...queryParams.value
|
||||
}, `tags_${new Date().getTime()}.xlsx`)
|
||||
}
|
||||
|
||||
/** 获取名称拼音做为固定链接地址 */
|
||||
function changeName() {
|
||||
form.value.slug = pinyin(form.value.name, {toneType: 'none', nonZh: 'consecutive', separator: '-'});
|
||||
}
|
||||
|
||||
getList();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.el-input-group__append {
|
||||
padding: 0;
|
||||
}
|
||||
.color-dot {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.dot {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 1px solid;
|
||||
border-radius: 50%;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user