书签 删除功能

This commit is contained in:
simple321vip
2022-04-05 00:52:20 +08:00
parent 2bbb02ef3d
commit 5c78d43302
5 changed files with 92 additions and 81 deletions
+2 -4
View File
@@ -24,12 +24,10 @@ const update_bookmark = (params: Object) => {
}) })
} }
const delete_bookmark = (params: Object) => { const delete_bookmark = (query: number) => {
return request({ return request({
url: '/bookmark', url: '/bookmark/delete/' + query,
method: 'delete', method: 'delete',
headers: {},
data: params
}) })
} }
-52
View File
@@ -1,52 +0,0 @@
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
</p>
<p>See <code>README.md</code> for more information.</p>
<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Docs
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
</p>
<button type="button" @click="count++">count is: {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>
<style scoped>
a {
color: #42b983;
}
label {
margin: 0 0.5em;
font-weight: bold;
}
code {
background-color: #eee;
padding: 2px 4px;
border-radius: 4px;
color: #304455;
}
</style>
+29
View File
@@ -0,0 +1,29 @@
<template>
<span class="dialog-footer">
<el-button @click="concel">取消</el-button>
<el-button type="primary" @click="submit">确认</el-button>
</span>
</template>
<script setup lang="ts">
type Props = {
delete_id: any
}
const props = defineProps<Props>()
const emit = defineEmits(['on-concel', 'on-submit'])
const concel = () => {
emit('on-concel')
}
const submit = () => {
emit('on-submit', props.delete_id)
}
</script>
<style>
.dashboard {
background-color: beige;
}
</style>
+7 -5
View File
@@ -2,10 +2,11 @@
<div class="dashboard"> <div class="dashboard">
<el-form :model="dialog_form"> <el-form :model="dialog_form">
<el-form-item label="分类" :label-width="formLabelWidth"> <el-form-item label="分类" :label-width="formLabelWidth">
<el-select v-model="dialog_form.bk_type_id" placeholder="请选择"> <el-select v-model="dialog_form.bk_type_name" placeholder>
<el-option <el-option
v-for="(item, index) in types" v-for="(item, index) in types"
:key="index" :key="index"
:selected="index == 1 ? 'selected' : ''"
:value="item.bk_type_id" :value="item.bk_type_id"
:label="item.bk_type_name" :label="item.bk_type_name"
/> />
@@ -28,7 +29,9 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { reactive } from 'vue';
import { update_bookmark, put_bookmark } from '../../api/bookmark' import { update_bookmark, put_bookmark } from '../../api/bookmark'
import type { FormInstance } from 'element-plus'
const formLabelWidth = '140px' const formLabelWidth = '140px'
type Props = { type Props = {
@@ -43,7 +46,6 @@ const concel = () => {
emit('on-concel') emit('on-concel')
} }
const submit = () => { const submit = () => {
const params = { const params = {
bk_id: props.dialog_form.bk_id, bk_id: props.dialog_form.bk_id,
bk_type_id: props.dialog_form.bk_type_id, bk_type_id: props.dialog_form.bk_type_id,
@@ -53,15 +55,15 @@ const submit = () => {
if (props.operate_code == '0') { if (props.operate_code == '0') {
put_bookmark(params).then(response => { put_bookmark(params).then(response => {
emit('on-submit', props.dialog_form) emit('on-submit')
}) })
} else if (props.operate_code == '1') { } else if (props.operate_code == '1') {
update_bookmark(params).then(response => { update_bookmark(params).then(response => {
emit('on-submit', props.dialog_form) emit('on-submit')
}) })
} else if (props.operate_code == '2') { } else if (props.operate_code == '2') {
update_bookmark(params).then(response => { update_bookmark(params).then(response => {
emit('on-submit', props.dialog_form) emit('on-submit')
}) })
} }
} }
+54 -20
View File
@@ -29,7 +29,7 @@
type="success" type="success"
v-for="(item) in bookmark_types" v-for="(item) in bookmark_types"
@click="doSearch(item.id)" @click="doSearch(item.id)"
>{{ item.type }}</el-tag> >{{ item.bk_type_name }}</el-tag>
</div> </div>
</el-form> </el-form>
<div></div> <div></div>
@@ -47,12 +47,11 @@
<el-table-column class="click-icon" prop="url" label="url" /> <el-table-column class="click-icon" prop="url" label="url" />
<el-table-column class="click-icon" prop label="操作"> <el-table-column class="click-icon" prop label="操作">
<template #default="scope"> <template #default="scope">
<el-button size="small" @click="handleEdit(scope.$index, scope.row)">Edit</el-button> <el-icon :size="20" @click="copyNumber(scope.row)" class="click-icon">
<el-button <CopyDocument />
size="small" </el-icon>
type="danger" <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
@click="handleDelete(scope.$index, scope.row)" <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
>Delete</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@@ -60,6 +59,7 @@
<el-button @click="toggleSelection([tableData[1], tableData[2]])">反选</el-button> <el-button @click="toggleSelection([tableData[1], tableData[2]])">反选</el-button>
<el-button @click="toggleSelection()">清除</el-button> <el-button @click="toggleSelection()">清除</el-button>
</div> </div>
<el-dialog v-model="dialogFormVisible" title="添加书签"> <el-dialog v-model="dialogFormVisible" title="添加书签">
<bookmark_dialog <bookmark_dialog
:dialog_form="currentDialogData" :dialog_form="currentDialogData"
@@ -69,15 +69,24 @@
@on-submit="doSubmit" @on-submit="doSubmit"
></bookmark_dialog> ></bookmark_dialog>
</el-dialog> </el-dialog>
<el-dialog v-model="dialogVisible">
<delete_dialog :delete_id="currentDialogData.bk_id" @on-submit="doDelete"></delete_dialog>
</el-dialog>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
import { search_bookmark } from '../../api/bookmark' import { search_bookmark, delete_bookmark } from '../../api/bookmark'
import { bookmark_type } from '../../api/master' import { bookmark_type } from '../../api/master'
import bookmark_dialog from './dialog.vue' import bookmark_dialog from './dialog.vue'
import delete_dialog from '../../components/operate/deleteDialog.vue'
import type { ElTable } from 'element-plus' import type { ElTable } from 'element-plus'
import { CopyDocument } from "@element-plus/icons-vue";
import { ElNotification } from 'element-plus'
import copy from 'copy-to-clipboard';
import { h } from 'vue'
const bookmark_types = reactive<any[]>([]) const bookmark_types = reactive<any[]>([])
@@ -94,15 +103,13 @@ bookmark_type().then(response => {
// 定义书签格式 // 定义书签格式
type Bookmark = { type Bookmark = {
id: number, bk_id: number,
bk_type_id: number, bk_type_id: number,
bk_type_name: String, bk_type_name: String,
comment: String, comment: String,
url: String url: String
} }
// dialog表示flag
let dialogFormVisible = ref(false)
// 操作code // 操作code
let operate = ref<String>('') let operate = ref<String>('')
const search_data = reactive({ const search_data = reactive({
@@ -112,9 +119,9 @@ const search_data = reactive({
const tableData = reactive<Bookmark[]>([]) const tableData = reactive<Bookmark[]>([])
// 响应式dialog数据 // 响应式dialog数据
const currentDialogData = reactive<Bookmark>({ const currentDialogData = reactive<Bookmark>({
id: 0, bk_id: -1,
bk_type_id: 0, bk_type_id: 1,
bk_type_name: '', bk_type_name: '未分类',
comment: '', comment: '',
url: '' url: ''
}) })
@@ -134,15 +141,27 @@ const toggleSelection = (rows?: Bookmark[]) => {
} }
// dialog表示flag
let dialogFormVisible = ref(false)
let dialogVisible = ref(false)
// 操作-》添加
const handleInsert = () => { const handleInsert = () => {
operate.value = '0' operate.value = '0'
// currentDialogData currentDialogData.bk_id = -1
currentDialogData.bk_type_id = 1
currentDialogData.bk_type_name = '未分类'
currentDialogData.comment = ''
currentDialogData.url = ''
dialogFormVisible.value = true dialogFormVisible.value = true
} }
// 操作-》删除
const handleDelete = (index: number, bookmark: Bookmark) => { const handleDelete = (index: number, bookmark: Bookmark) => {
Object.assign(currentDialogData, bookmark)
operate.value = '2' operate.value = '2'
dialogFormVisible.value = true dialogVisible.value = true
} }
// 操作-》编辑
const handleEdit = (index: number, bookmark: Bookmark) => { const handleEdit = (index: number, bookmark: Bookmark) => {
Object.assign(currentDialogData, bookmark) Object.assign(currentDialogData, bookmark)
operate.value = '1' operate.value = '1'
@@ -150,7 +169,6 @@ const handleEdit = (index: number, bookmark: Bookmark) => {
} }
const handleSelectionChange = (val: Bookmark[]) => { const handleSelectionChange = (val: Bookmark[]) => {
console.log(val)
multipleSelection.value = val multipleSelection.value = val
} }
@@ -165,7 +183,7 @@ const doSearch = (type_id: String) => {
response.data.forEach((item: Bookmark, index: number) => { response.data.forEach((item: Bookmark, index: number) => {
console.log(item) console.log(item)
const row = { const row = {
id: index + 1, bk_id: item.bk_id,
bk_type_id: item.bk_type_id, bk_type_id: item.bk_type_id,
bk_type_name: item.bk_type_name, bk_type_name: item.bk_type_name,
comment: item.comment, comment: item.comment,
@@ -176,15 +194,31 @@ const doSearch = (type_id: String) => {
}) })
} }
const doDelete = (delete_id: any) => {
let query = delete_id
delete_bookmark(query).then(response => {
dialogVisible.value = false
})
dialogVisible.value = false
}
const closeDialog = () => { const closeDialog = () => {
dialogFormVisible.value = false dialogFormVisible.value = false
} }
const doSubmit = (form: any) => { const doSubmit = () => {
dialogFormVisible.value = false dialogFormVisible.value = false
} }
// 复制转换成功的数值,并提示 复制成功 信息
const copyNumber = (record: Bookmark) => {
copy(record.url + "")
ElNotification({
title: '',
message: h('i', { style: 'color: teal' }, '复制成功'),
})
}
</script> </script>
<style> <style scoped>
/* .dashboard { /* .dashboard {
background-color: beige; background-color: beige;
} */ } */