diff --git a/src/App.vue b/src/App.vue
index 34f9dcc..36cd429 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -19,10 +19,10 @@ export default {
$route: function(to, from) {
const path = to.path
if (path.indexOf('/login') < 0) {
- if (path.indexOf('_m') > 0 && this.$pc) {
+ if (path === '/_m' && this.$pc) {
this.$router.push(path.split('_m')[0])
- } else if (path.indexOf('_m') < 0 && !this.$pc) {
- this.$router.push(path + '_m')
+ } else if (path === '/' && !this.$pc) {
+ this.$router.push('/_m')
}
}
}
diff --git a/src/api/markdown-api.js b/src/api/markdown-api.js
index 7060e02..c6c89bc 100644
--- a/src/api/markdown-api.js
+++ b/src/api/markdown-api.js
@@ -10,7 +10,7 @@ export default {
params
})
},
- // 获取markdown内容 /markdown/add
+ // 添加文档 /markdown/add
addMarkdown: function(data) {
return request({
url: '/markdown/add',
@@ -18,4 +18,12 @@ export default {
data
})
},
+ // 编辑文档 /markdown/edit
+ editMarkdown: function(data) {
+ return request({
+ url: '/markdown/edit',
+ method: 'post',
+ data
+ })
+ },
}
diff --git a/src/icons/svg/menu-edit1.svg b/src/icons/svg/menu-edit1.svg
new file mode 100644
index 0000000..099dc9c
--- /dev/null
+++ b/src/icons/svg/menu-edit1.svg
@@ -0,0 +1 @@
+
diff --git a/src/router/index.js b/src/router/index.js
index 17abc84..d486f52 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -117,10 +117,10 @@ export const constantRoutes = [
component: Layout,
children: [
{
- path: 'index',
+ path: 'editor',
name: 'markdown',
component: () => import('@/views/markdown/index'),
- meta: { title: '创建文档', icon: 'md' }
+ // meta: { title: '创建文档', icon: 'md' }
}
]
},
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index 467859c..ca7ea09 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -25,7 +25,7 @@
-
@@ -335,6 +335,16 @@ export default {
{ iconClass: 'menu-download', label: '下载', operation: 'download' },
{ iconClass: 'menu-remove', label: '删除', operation: 'remove' }
],
+ singleMenusEdit: [
+ { iconClass: 'menu-open', label: '打开', operation: 'open' },
+ { iconClass: 'menu-favorite', label: '收藏', operation: 'favorite' },
+ { iconClass: 'menu-edit1', label: '编辑', operation: 'edit' },
+ { iconClass: 'menu-details', label: '详细信息', operation: 'details' },
+ { iconClass: 'menu-rename', label: '重命名', operation: 'rename' },
+ { iconClass: 'menu-copy', label: '移动或复制', operation: 'copy' },
+ { iconClass: 'menu-download', label: '下载', operation: 'download' },
+ { iconClass: 'menu-remove', label: '删除', operation: 'remove' }
+ ],
multipleMenus: [
{ iconClass: 'menu-copy', label: '移动或复制', operation: 'copy' },
{ iconClass: 'menu-download', label: '下载', operation: 'download' },
@@ -632,7 +642,7 @@ export default {
},
// 新建文档
newDocument() {
-
+ this.$router.push(`/markdown/editor`)
},
newFolder() {
this.newFolderName = '新建文件夹'
@@ -1012,7 +1022,11 @@ export default {
// 更多操作(单选)
moreClick(row, event) {
this.menusIsMultiple = false
- this.menus = this.singleMenus
+ if(row.contentType && row.contentType.includes("text")){
+ this.menus = this.singleMenusEdit
+ }else{
+ this.menus = this.singleMenus
+ }
this.showOperationMenus(event)
this.preliminaryRowData(row)
this.showOperationMenus(event)
@@ -1024,7 +1038,11 @@ export default {
this.menus = this.multipleRightMenus
} else {
this.menusIsMultiple = false
- this.menus = this.singleMenus
+ if(row.contentType && row.contentType.includes("text")){
+ this.menus = this.singleMenusEdit
+ }else{
+ this.menus = this.singleMenus
+ }
this.preliminaryRowData(row)
}
// 右击选择的数据
@@ -1108,6 +1126,10 @@ export default {
console.log('operation', '收藏')
this.favoriteOperating(true)
break
+ case 'edit':
+ console.log('edit', '编辑')
+ this.$router.push(`/markdown/editor?id=${this.rowContextData.id}`)
+ break
case 'open':
console.log('open', '打开')
this.fileClick(this.rowContextData)
diff --git a/src/views/home/mobile/index.vue b/src/views/home/mobile/index.vue
index 5a12faa..c4b6787 100644
--- a/src/views/home/mobile/index.vue
+++ b/src/views/home/mobile/index.vue
@@ -624,7 +624,7 @@
}
})
if(isPushLink){
- this.$router.push(`/_m?path=${this.path}`)
+ this.$router.push(`/_m?path=${encodeURIComponent(this.path)}`)
}
setPath(this.path, this.pathList)
this.getFileList()
@@ -762,14 +762,20 @@
item2['index'] = this.pathList.length
this.pathList[this.pathList.length - 1] = item1
this.pathList.push(item2)
- this.$router.push(`/_m?path=${this.path}`)
+ this.$router.push(`/_m?path=${encodeURIComponent(this.path)}`)
setPath(this.path, this.pathList)
this.getFileList()
} else {
- // 打开文件
- const fileIds = [row.id]
- const url = process.env.VUE_APP_BASE_FILE_API + 'preview/' + row.name + '?jmal-token=' + this.$store.state.user.token + '&fileIds=' + fileIds
- window.open(url, '_blank')
+ if(row.contentType.includes('text')){
+ // let routeData = this.$router.resolve({path: '/public/p',query: {mark: row.id}})
+ // window.open(routeData.href, '_blank');
+ this.$router.push(`/public/p?mark=${row.id}`)
+ }else{
+ // 打开文件
+ const fileIds = [row.id]
+ const url = process.env.VUE_APP_BASE_FILE_API + 'preview/' + row.name + '?jmal-token=' + this.$store.state.user.token + '&fileIds=' + fileIds
+ window.open(url, '_blank')
+ }
}
}
},
diff --git a/src/views/markdown/index.vue b/src/views/markdown/index.vue
index 8787b2f..4fc31be 100644
--- a/src/views/markdown/index.vue
+++ b/src/views/markdown/index.vue
@@ -5,7 +5,8 @@
.md
- 发布文章
+ 发布文章
+ 更新文章
@@ -13,7 +14,10 @@
v-model="content"
ref="md"
@change="change"
+ codeStyle="atelier-dune-dark"
:style="{'height': clientHeight+'px'}"
+ :imageFilter="imageFilter"
+ @save="save"
/>
@@ -24,49 +28,25 @@
export default {
data() {
return {
- content:"# 一级标题\n" +
- "```java\n" +
- "import markdownApi from '@/api/markdown-api'\n" +
- " export default {\n" +
- " data() {\n" +
- " return {\n" +
- " content:'', // 输入的markdown\n" +
- " html:'', // 及时转的html\n" +
- " }\n" +
- " },\n" +
- " methods: {\n" +
- " // 所有操作都会被解析重新渲染\n" +
- " change(value, render){\n" +
- " console.log(value)\n" +
- " // render 为 markdown 解析后的结果[html]\n" +
- " this.html = render;\n" +
- " },\n" +
- " // 提交\n" +
- " submit(){\n" +
- " console.log(this.content);\n" +
- " console.log(this.html);\n" +
- " markdownApi.addMarkdown({\n" +
- " userId: this.$store.state.user.userId,\n" +
- " username: this.$store.state.user.name,\n" +
- " filename: this.filename+\".md\"\n" +
- " }).then((res) => {\n" +
- "\n" +
- " console.log(res.data)\n" +
- " })\n" +
- " }\n" +
- " },\n" +
- " mounted() {\n" +
- "\n" +
- " }\n" +
- " }\n" +
- "```\n" +
- "## 二级标题", // 输入的markdown
+ editStatus: false,
+ content:"", // 输入的markdown
html:'', // 及时转的html
filename: '新建文档',
- clientHeight: document.documentElement.clientHeight - 155
+ clientHeight: document.documentElement.clientHeight - 155,
+ updating: false,
+ adding: false,
}
},
mounted() {
+ if(this.$route.query.id){
+ this.editStatus = true
+ markdownApi.getMarkdown({
+ mark: this.$route.query.id
+ }).then((res) => {
+ this.content = res.data.contentText
+ this.filename = res.data.name.split('.md')[0]
+ })
+ }
const that = this
window.onresize = function temp() {
that.clientHeight = document.documentElement.clientHeight - 155
@@ -75,14 +55,23 @@
methods: {
// 所有操作都会被解析重新渲染
change(value, render){
- console.log(value)
// render 为 markdown 解析后的结果[html]
this.html = render;
},
- // 提交
- submit(){
- console.log(this.content);
- console.log(this.html);
+ save() {
+ if(this.editStatus){
+ this.update()
+ }else{
+ this.add()
+ }
+ },
+ imageFilter() {
+ console.log('imageFilter')
+ return true
+ },
+ // add
+ add(){
+ this.adding = true
if(this.filename){
const filename = this.filename + ".md"
markdownApi.addMarkdown({
@@ -91,7 +80,34 @@
filename: filename,
contentText: this.content
}).then((res) => {
- console.log(res.data)
+ this.adding = false
+ this.$message({
+ message: "发布成功",
+ type: 'success',
+ duration : 1000
+ });
+ this.$router.push(`/`)
+ })
+ }
+ },
+ // update
+ update(){
+ this.updating = true
+ if(this.filename){
+ const filename = this.filename + ".md"
+ markdownApi.editMarkdown({
+ fileId: this.$route.query.id,
+ userId: this.$store.state.user.userId,
+ username: this.$store.state.user.name,
+ filename: filename,
+ contentText: this.content
+ }).then(() => {
+ this.updating = false
+ this.$message({
+ message: "更新成功",
+ type: 'success',
+ duration : 1000
+ });
})
}
}
diff --git a/src/views/public/p/index.vue b/src/views/public/p/index.vue
index e164fca..be7123a 100644
--- a/src/views/public/p/index.vue
+++ b/src/views/public/p/index.vue
@@ -6,17 +6,20 @@
{{leftContent}}d
-
+
+
+
@@ -49,9 +52,10 @@
toolbars:{
navigation: true,
},
- toolbarsFlag: false,
+ toolbarsFlag: true,
content:'',
html:'',
+ clientHeight: document.documentElement.clientHeight - 155,
}
},
mounted() {
@@ -59,6 +63,10 @@
this.showList = false
}
this.getMarkDown()
+ const that = this
+ window.onresize = function temp() {
+ that.clientHeight = document.documentElement.clientHeight - 155
+ }
},
methods: {
onScroll() {