feat:增加添加书签功能

This commit is contained in:
CN32479-詹红柱 2021-08-14 16:18:44 +08:00
parent 1f216d9324
commit 2c5ba8a454
3 changed files with 124 additions and 4488 deletions

View File

@ -55,7 +55,7 @@
</div> </div>
</div> </div>
</div> </div>
<Dialog v-model="isDetailVisible" @closeViews="closeViews" /> <Dialog class="my-dialog" v-model="isDetailVisible" @closeViews="closeViews" :selectType="activeIndex" @fresh="search"/>
</template> </template>
<script> <script>
@ -64,7 +64,19 @@ import { myData } from './assets/Json/印象笔记.js'
import { watch } from '@vue/runtime-core' import { watch } from '@vue/runtime-core'
import Dialog from './components/Dialog.vue' import Dialog from './components/Dialog.vue'
import gsap from 'gsap' import gsap from 'gsap'
var rowData = myData var rowData = []
function getData(fn = () => {}) {
//
if (localStorage.getItem('BOOKMARK')) {
console.log('持久化数据')
rowData = JSON.parse(localStorage.getItem('BOOKMARK'))
} else {
localStorage.setItem('BOOKMARK', JSON.stringify(myData))
rowData = myData
}
fn()
}
getData()
export default { export default {
components: { Dialog }, components: { Dialog },
name: 'kestrel-bookmark', name: 'kestrel-bookmark',
@ -72,10 +84,13 @@ export default {
// //
const flatten = (arr, result = []) => { const flatten = (arr, result = []) => {
for (const item of arr) { for (const item of arr) {
Array.isArray(item.children) ? flatten(item.children, result) : result.push(item) Array.isArray(item.children)
? flatten(item.children, result)
: result.push(item)
} }
return result return result
} }
const data = reactive({ const data = reactive({
activeIndex: 0, activeIndex: 0,
data: rowData, data: rowData,
@ -95,25 +110,32 @@ export default {
) )
} }
) )
// //
const selectType = (item, index) => { const selectType = (item, index) => {
data.bookMark = item.children data.bookMark = item.children
data.activeIndex = index data.activeIndex = index
} }
// //
const navigate = (v) => window.open(v.url, '_target') const navigate = (v) => window.open(v.url, '_target')
// //
const add = () => (data.isDetailVisible = !data.isDetailVisible) const add = () => (data.isDetailVisible = !data.isDetailVisible)
// //
const closeViews = (v) => (data.isDetailVisible = v) const closeViews = (v) => (data.isDetailVisible = v)
const search = async () => {
console.log('---->')
await getData(() => {
data.bookMark = rowData[data.activeIndex].children
})
}
return { return {
...toRefs(data), ...toRefs(data),
selectType, selectType,
navigate, navigate,
add, add,
closeViews closeViews,
search
} }
}, },
methods: { methods: {

File diff suppressed because one or more lines are too long

View File

@ -1,16 +1,48 @@
<template> <template>
<el-dialog title="提示" :visible="isDetailVisible" width="30%" :before-close="handleClose"> <el-dialog custom-class="my-dialog" title="新增书签" :visible="isDetailVisible" width="758px">
<span>这是一段信息</span> <el-form status-icon ref="refruleForm" :rules="rules" :model="ruleForm" label-width="100px" size="small">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="书签名称" prop="title">
<el-input v-model="ruleForm.title" placeholder="请输入书签名称"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="书签类别" prop="type">
<el-select v-model="ruleForm.type" placeholder="请选择书签类别" style="width:100%">
<el-option v-for="(item,index) in BOOKMARK" :value="item" :key="index"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="LOGO地址" prop="logo">
<el-input v-model="ruleForm.logo" placeholder="请输入LOGO地址"></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="访问地址" prop="url">
<el-input v-model="ruleForm.url" placeholder="请输入访问绝对地址"></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="书签描述" prop="desc">
<el-input type="textarea" clearable placeholder="请输入书签描述" v-model="ruleForm.desc" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="closeViews"> </el-button> <el-button @click="closeViews"> </el-button>
<el-button type="primary" @click="closeViews"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script> <script>
import gsap from 'gsap' import gsap from 'gsap'
import { reactive, ref } from '@vue/reactivity'
import { nextTick } from '@vue/runtime-core'
export default { export default {
model: { model: {
value: 'isDetailVisible', value: 'isDetailVisible',
@ -20,14 +52,65 @@ export default {
isDetailVisible: { isDetailVisible: {
type: Boolean, type: Boolean,
default: false default: false
},
selectType: {
type: Number,
default: 0
} }
}, },
setup(props, context) { setup(props, context) {
const closeViews = () => { const isBOOKMARK = JSON.parse(localStorage.getItem('BOOKMARK'))
const BOOKMARK = isBOOKMARK ? isBOOKMARK.map((v) => v.type) : []
const ruleForm = reactive({
title: '',
type: '',
desc: '',
url: '',
logo: ''
})
// :rules
const rules = {
title: [{ required: true, message: '请输入书签名称', trigger: 'blur' }],
type: [{ required: true, message: '请选择书签类别', trigger: 'change' }]
}
const refruleForm = ref(null)
//
console.log('--->', isBOOKMARK)
const submitForm = () => {
refruleForm.value.validate((valid) => {
if (valid) {
console.log(isBOOKMARK)
const myData = isBOOKMARK.map((v) => {
if (v.type === ruleForm.type) {
v.children.push({ ...ruleForm })
}
return v
})
console.log(myData)
localStorage.setItem('BOOKMARK', JSON.stringify(myData))
context.emit('fresh')
closeViews()
} else {
return false
}
})
}
function closeViews() {
refruleForm.value.resetFields()
context.emit('closeViews', false) context.emit('closeViews', false)
} }
//
nextTick(() => {
ruleForm.type = isBOOKMARK ? BOOKMARK[props.selectType] : ''
})
return { return {
closeViews ruleForm,
closeViews,
submitForm,
refruleForm,
rules,
BOOKMARK
} }
}, },
methods: { methods: {
@ -56,65 +139,14 @@ export default {
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.card-s { .my-dialog {
position: fixed; background: red;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 2000;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
overflow: auto;
display: flex;
justify-content: center;
align-items: center;
} }
.tel-cont { .my-dialog /deep/.el-dialog__header {
width: 40%; border-bottom: 1px solid #eee !important;
min-width: 600px;
min-height: 440px;
position: relative;
margin-top: 0px;
background: #fff;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
box-sizing: border-box;
.el-dialog__header {
padding: 20px 20px 10px;
width: 100%;
border-bottom: 1px solid #eee;
.el-dialog__title {
line-height: 24px;
font-size: 18px;
color: #303133;
}
.el-dialog__headerbtn {
position: absolute;
top: 20px;
right: 20px;
padding: 0;
background: transparent;
border: none;
outline: none;
cursor: pointer;
font-size: 16px;
}
}
} }
.list-complete-item { .my-dialog /deep/.el-dialog__title {
transition: all 0.8s ease; font-size: 16px;
display: inline-block; color: #e03b5d;
margin-right: 10px;
}
.list-complete-enter-from,
.list-complete-leave-to {
opacity: 0;
transform: translateY(30px);
}
.list-complete-leave-active {
position: absolute;
} }
</style> </style>