文档编辑模式

This commit is contained in:
satori 2022-02-05 12:52:28 +08:00
parent db75223449
commit 42bb51bf4e
3 changed files with 131 additions and 48 deletions

63
pages/docs.vue Normal file
View File

@ -0,0 +1,63 @@
<template lang="pug">
.docs-index
.docs.circumscription
.outline
ul
li 下载安装
li 接口使用
li 插件制作
li 基础开发
li(v-for="item in list", :key="item._id")
NuxtLink(:to="`/docs/${item._id}`") {{ item.name }}
.create-doc
button(@click="createin = !createin") Create
.content
Nuxt
</template>
<script>
export default {
asyncData({ $axios }) {
return $axios.get("/api/docs").then((res) => {
return {
list: res.data,
doc: { name: "未命名文档", data: "输入内容" },
createin: false,
};
});
},
methods: {
submit() {
this.$axios.post("/api/docs", this.doc).then((res) => {
console.log(res.data);
});
},
},
};
</script>
<style lang="sass">
.docs-index
margin: 8rem 4rem
.docs
display: flex
width: 100%
.outline
width: 12rem
padding: 2rem
background: #ccefef
.content
padding: 2rem
background: #ffefef
flex: 1
input.title, textarea.data
width: 100%
background: none
border: none
padding: 1rem 2rem
box-sizing: border-box
font-size: 1rem
input.title
font-size: 1.5rem
</style>

68
pages/docs/_id.vue Normal file
View File

@ -0,0 +1,68 @@
<template lang="pug">
.docs-item
button.editor(@click="editor()") {{ edit ? '取消编辑' : '编辑模式' }}
button.submit(@click="submit()", v-if="edit") 保存修改
.contenter(v-if="!edit")
h1.title {{ data.name }}
p {{ data.data }}
.contenter(v-else)
input.title(v-model="doc.name")
textarea.data(v-model="doc.data", rows="32")
</template>
<script>
export default {
asyncData({ $axios, params }) {
return $axios.get(`/api/docs/${params.id}`).then((res) => {
return { data: res.data, edit: false, doc: { data: "", name: "" } };
});
},
methods: {
editor() {
if (!this.eidt) {
this.doc.name = this.data.name;
this.doc.data = this.data.data;
}
this.edit = !this.edit;
},
submit() {
this.$axios.patch(`/api/docs/${this.data._id}`, this.doc).then((res) => {
if (res.status === 200) {
this.data.name = this.doc.name;
this.data.data = this.doc.data;
this.edit = false;
}
console.log(res.data);
});
},
},
};
</script>
<style lang="sass">
.docs-item
position: relative
.editor
position: absolute
top: 0
right: 0
.submit
position: absolute
top: 0
right: 6rem
background: #14cc14
h1
margin-top: 0
input.title, textarea.data
width: 100%
background: none
border: none
padding: 1rem 2rem
box-sizing: border-box
font-size: 1rem
input.title
font-size: 1.5rem
input:focus, textarea:focus
border: none
</style>

View File

@ -1,48 +0,0 @@
<template lang="pug">
.docs-index
.docs.circumscription
.outline
ul
li 下载安装
li 接口使用
li 插件制作
li 基础开发
.content
p 其构建目的是使实现所需越简单越好,, 避免仅为实现一个简单功能而牵涉到一堆较深层级的知识体系
p SDK
p 由于实现前端功能为直接目标, 为避免牵涉到其它知识体系, 此处将基于cookie的登录与权限判定逻辑均装入js库以直接调用
p
div
p import kana from 'kana-sdk'
p
p const ctx = new Kana() // , ,
p console.log(ctx.title) //
p console.log(ctx.info) //
p console.log(ctx.list) // , Map()
p
p const threadlist = ctx.list.get("thread") // thread
p console.log(threadlist) //
p console.log(threadlist[1].posts) //
p console.log(threadlist[1].posts[1].data) //
p console.log(threadlist[1].posts[1].user.name) //
p
p 维度是可变的
p ctx.list.get("post")
p 按照某一条件检索获得post列表
</template>
<style lang="sass">
.docs-index
margin: 8rem 4rem
.docs
display: flex
width: 100%
.outline
width: 12rem
padding: 2rem
background: #ccefef
.content
padding: 2rem
background: #ffefef
flex: 1
</style>