Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Selicens
在线问答社区
提交
e124e670
在
在线问答社区
项目概览
Selicens
/
在线问答社区
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
在
在线问答社区
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e124e670
编写于
5月 09, 2023
作者:
6
628992d768790c7144c1f639
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tue May 9 14:52:00 UTC 2023 inscode
上级
6591445e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
320 addition
and
47 deletion
+320
-47
src/components/nav/index.vue
src/components/nav/index.vue
+2
-1
src/router/index.js
src/router/index.js
+5
-0
src/stores/article.js
src/stores/article.js
+22
-12
src/utils/mockData.js
src/utils/mockData.js
+34
-23
src/views/DetailsArticle.vue
src/views/DetailsArticle.vue
+199
-0
src/views/HomeView.vue
src/views/HomeView.vue
+21
-8
src/views/NewArticle.vue
src/views/NewArticle.vue
+37
-3
未找到文件。
src/components/nav/index.vue
浏览文件 @
e124e670
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
console
.
log
(
value
);
console
.
log
(
value
);
store
.
sigin
(
userModalConfig
);
store
.
sigin
(
userModalConfig
);
vibisible
.
value
=
false
;
vibisible
.
value
=
false
;
userStatus
.
value
=
store
.
isRejecter
();
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
}
}
...
@@ -62,7 +63,7 @@
...
@@ -62,7 +63,7 @@
<a-col
:span=
"5"
v-if=
"width > 750"
>
<a-col
:span=
"5"
v-if=
"width > 750"
>
<a-row
:gutter=
"5"
>
<a-row
:gutter=
"5"
>
<a-col
:span=
"18"
class=
"nav-right"
>
<a-col
:span=
"18"
class=
"nav-right"
>
<a-input-search
:value=
"width"
></a-input-search>
<a-input-search></a-input-search>
</a-col>
</a-col>
<a-col
:span=
"5"
>
<a-col
:span=
"5"
>
<a-dropdown>
<a-dropdown>
...
...
src/router/index.js
浏览文件 @
e124e670
...
@@ -21,6 +21,11 @@ const router = createRouter({
...
@@ -21,6 +21,11 @@ const router = createRouter({
path
:
'
/newArticle
'
,
path
:
'
/newArticle
'
,
name
:
'
newArticle
'
,
name
:
'
newArticle
'
,
component
:
()
=>
import
(
'
../views/NewArticle.vue
'
)
component
:
()
=>
import
(
'
../views/NewArticle.vue
'
)
},
{
path
:
'
/detailsArticle
'
,
name
:
'
detailsArticle
'
,
component
:
()
=>
import
(
'
../views/DetailsArticle.vue
'
)
}
}
]
]
})
})
...
...
src/stores/article.js
浏览文件 @
e124e670
...
@@ -4,29 +4,39 @@ import { getStorage, setStorage } from '@/utils/storage'
...
@@ -4,29 +4,39 @@ import { getStorage, setStorage } from '@/utils/storage'
export
const
useArticleStore
=
defineStore
(
'
article
'
,
()
=>
{
export
const
useArticleStore
=
defineStore
(
'
article
'
,
()
=>
{
const
articles
=
reactive
([])
const
articles
=
reactive
([])
const
setArticle
=
(
id
,
data
)
=>
{
const
addAtricle
=
(
data
)
=>
{
let
atc
=
getArticle
(
id
)
const
atc
=
getAllArticle
()
if
(
atc
)
{
if
(
!
atc
)
{
atc
=
data
articles
.
unshift
(
data
)
}
else
{
articles
.
push
(
data
)
console
.
log
(
articles
);
console
.
log
(
articles
);
setStorage
(
'
article
'
,
articles
)
setStorage
(
'
article
'
,
articles
)
}
else
{
console
.
log
(
atc
)
atc
.
unshift
(
data
)
setStorage
(
'
article
'
,
atc
)
}
}
}
}
const
getArticle
=
(
id
)
=>
{
const
setArticle
=
(
id
,
data
)
=>
{
const
atc
=
getAllArticle
()
??
false
let
atcs
=
getAllArticle
()
??
false
if
(
atc
)
{
if
(
atcs
)
{
return
atc
.
filter
(
item
=>
item
.
id
===
id
)
atcs
.
forEach
(
item
=>
{
if
(
item
.
id
==
id
)
{
console
.
log
(
item
)
item
.
comment
.
unshift
(
data
)
}
})
console
.
log
(
atcs
)
setStorage
(
'
article
'
,
atcs
)
}
}
}
}
const
getAllArticle
=
()
=>
{
const
getAllArticle
=
()
=>
{
return
getStorage
(
'
article
'
)
return
getStorage
(
'
article
'
)
}
}
return
{
return
{
articles
,
articles
,
addAtricle
,
setArticle
,
setArticle
,
getArticle
,
getAllArticle
,
getAllArticle
,
}
}
})
})
\ No newline at end of file
src/utils/mockData.js
浏览文件 @
e124e670
export
const
mockData
=
[
export
const
mockData
=
[
{
{
id
:
'
01
'
,
id
:
'
01
'
,
username
:
'
adm
in
'
,
username
:
'
just
in
'
,
date
:
new
Date
().
toLocaleString
(),
date
:
new
Date
().
toLocaleString
(),
content
:
{
content
:
{
title
:
'
震惊!原来日记可以唱出来
'
,
title
:
'
震惊!原来日记可以唱出来
'
,
abstract
:
'
11月20日零点,北京,小雨,心情好平静,今天做了很多事情,回到家里有点烦心
'
,
abstract
:
'
11月20日零点,北京,小雨,心情好平静,今天做了很多事情,回到家里有点烦心
'
,
article
:
''
,
article
:
'
,今天做了很多事情,回到家里有点烦心
'
,
}
},
comment
:
[
{
author
:
'
test
'
,
content
:
'
哈哈
'
,
datetime
:
'
2023/5/8 18:41:39
'
,
}
],
},
},
{
{
id
:
'
02
'
,
id
:
'
02
'
,
username
:
'
admin
'
,
username
:
'
lolita
'
,
date
:
new
Date
().
toLocaleString
(),
date
:
new
Date
().
toLocaleString
(),
content
:
{
content
:
{
title
:
'
震惊!原来日记可以唱出来
'
,
title
:
'
忘不掉的是回忆嘛?
'
,
abstract
:
'
11月20日零点,北京,小雨,心情好平静,今天做了很多事情,回到家里有点烦心
'
,
abstract
:
'
我多想忘掉回忆的坐标,但现实却是多么可笑,我们是从初次遇见不如不见到好久再见
'
,
article
:
''
,
article
:
'
我多想忘掉回忆的坐标,但现实却是多么可笑,我们是从初次遇见不如不见到好久再见
'
,
}
},
comment
:
[]
},
},
{
{
id
:
'
03
'
,
id
:
'
03
'
,
username
:
'
a
dmin
'
,
username
:
'
a
ngle
'
,
date
:
new
Date
().
toLocaleString
(),
date
:
new
Date
().
toLocaleString
(),
content
:
{
content
:
{
title
:
'
震惊!原来日记可以唱出来
'
,
title
:
'
我爱你iloveyou
'
,
abstract
:
'
11月20日零点,北京,小雨,心情好平静,今天做了很多事情,回到家里有点烦心
'
,
abstract
:
'
我以为我不会比今天更爱你了,但是我昨天也是这么想的,随时间流走在回忆里遨游
'
,
article
:
''
,
article
:
'
我以为我不会比今天更爱你了,但是我昨天也是这么想的,随时间流走在回忆里遨游
'
,
}
},
comment
:
[]
},
},
{
{
id
:
'
04
'
,
id
:
'
04
'
,
username
:
'
admin
'
,
username
:
'
toms
'
,
date
:
new
Date
().
toLocaleString
(),
date
:
new
Date
().
toLocaleString
(),
content
:
{
content
:
{
title
:
'
震惊!原来日记可以唱出来
'
,
title
:
'
原来这才是爱情
'
,
abstract
:
'
11月20日零点,北京,小雨,心情好平静,今天做了很多事情,回到家里有点烦心
'
,
abstract
:
'
如果你并不期待,那么我翻山越岭将毫无意义,细节是双向的,爱情是相互的
'
,
article
:
''
,
article
:
'
如果你并不期待,那么我翻山越岭将毫无意义,细节是双向的,爱情是相互的
'
,
}
},
comment
:
[]
},
},
{
{
id
:
'
05
'
,
id
:
'
05
'
,
username
:
'
admi
n
'
,
username
:
'
joh
n
'
,
date
:
new
Date
().
toLocaleString
(),
date
:
new
Date
().
toLocaleString
(),
content
:
{
content
:
{
title
:
'
震惊!原来日记可以唱出来
'
,
title
:
'
青春的真谛
'
,
abstract
:
'
11月20日零点,北京,小雨,心情好平静,今天做了很多事情,回到家里有点烦心
'
,
abstract
:
'
生活不得万分如意,现实不过千般磨砺,趁青春时可肆意,人海中,似有意,更似无意
'
,
article
:
''
,
article
:
'
生活不得万分如意,现实不过千般磨砺,趁青春时可肆意,人海中,似有意,更似无意
'
,
}
},
comment
:
[]
},
},
]
]
\ No newline at end of file
src/views/DetailsArticle.vue
0 → 100644
浏览文件 @
e124e670
<
script
setup
>
import
{
useRouter
,
useRoute
}
from
"
vue-router
"
;
import
{
useArticleStore
}
from
"
@/stores/article.js
"
;
import
{
getStorage
,
setStorage
}
from
"
@/utils/storage
"
;
import
dayjs
from
"
dayjs
"
;
import
{
LikeFilled
,
LikeOutlined
,
DislikeFilled
,
DislikeOutlined
,
}
from
"
@ant-design/icons-vue
"
;
import
{
ref
}
from
"
vue
"
;
import
relativeTime
from
"
dayjs/plugin/relativeTime
"
;
dayjs
.
extend
(
relativeTime
);
const
route
=
useRoute
();
const
{
id
,
username
,
content
,
date
,
comment
}
=
route
.
query
;
const
{
title
,
abstract
,
article
}
=
JSON
.
parse
(
content
);
const
store
=
useArticleStore
();
const
token
=
getStorage
(
"
token
"
);
console
.
log
(
token
);
const
comments
=
ref
([]);
if
(
JSON
.
parse
(
comment
).
length
>
0
)
{
console
.
log
(
JSON
.
parse
(
comment
));
comments
.
value
=
JSON
.
parse
(
comment
);
}
const
submitting
=
ref
(
false
);
const
value
=
ref
(
""
);
const
handleSubmit
=
()
=>
{
if
(
!
value
.
value
||
!
token
)
{
return
;
}
submitting
.
value
=
true
;
setTimeout
(()
=>
{
submitting
.
value
=
false
;
comments
.
value
=
[
{
author
:
token
.
username
,
content
:
value
.
value
,
datetime
:
dayjs
().
fromNow
(),
},
...
comments
.
value
,
];
console
.
log
(
comments
.
value
);
store
.
setArticle
(
id
,
{
author
:
token
.
username
,
content
:
value
.
value
,
datetime
:
new
Date
().
toLocaleString
(),
});
value
.
value
=
""
;
},
1000
);
};
const
likes
=
ref
(
0
);
const
dislikes
=
ref
(
0
);
const
action
=
ref
();
const
like
=
()
=>
{
likes
.
value
=
1
;
dislikes
.
value
=
0
;
action
.
value
=
"
liked
"
;
};
const
dislike
=
()
=>
{
likes
.
value
=
0
;
dislikes
.
value
=
1
;
action
.
value
=
"
disliked
"
;
};
const
imgReg
=
/<img.*
?
src=
[
'"
](
.*
?)[
'"
]
/gi
;
const
videoReg
=
/<source.*
?
src=
[
'"
](
.*
?)[
'"
]
/gi
;
const
imgSrc
=
ref
();
const
videoSrc
=
ref
();
if
(
imgReg
.
exec
(
article
))
{
imgReg
.
lastIndex
=
0
;
imgSrc
.
value
=
imgReg
.
exec
(
article
)[
1
];
console
.
log
(
imgSrc
.
value
);
}
if
(
videoReg
.
exec
(
article
))
{
videoReg
.
lastIndex
=
0
;
videoSrc
.
value
=
videoReg
.
exec
(
article
)[
1
];
console
.
log
(
videoSrc
.
value
);
}
</
script
>
<
template
>
<a-card>
<h2>
{{
title
}}
</h2>
<div
class=
"article-header"
>
<a-avatar></a-avatar>
<div>
<div>
<span
class=
"username"
>
{{
username
}}
</span>
</div>
<span
style=
"color: #515767"
>
{{
date
}}
阅读:
{{
Math
.
floor
(
Math
.
random
())
}}
</span
>
</div>
</div>
<div>
{{
abstract
}}
</div>
<div
v-if=
"imgSrc"
>
<img
:src=
"imgSrc"
/>
</div>
<div
v-if=
"videoSrc"
>
<video
controls
>
<source
:src=
"videoSrc"
/>
</video>
</div>
</a-card>
<a-card>
<h3>
评论
</h3>
<a-comment>
<template
#avatar
>
<a-avatar
/>
</
template
>
<
template
#content
>
<a-form-item>
<a-textarea
v-model:value=
"value"
/>
</a-form-item>
<a-form-item>
<a-button
html-type=
"submit"
:loading=
"submitting"
type=
"primary"
@
click=
"handleSubmit"
>
Add Comment
</a-button>
</a-form-item>
</
template
>
</a-comment>
<a-list
v-if=
"comments.length"
:data-source=
"comments"
:header=
"`${comments.length} ${
comments.length > 1 ? 'replies' : 'reply'
}`"
item-layout=
"horizontal"
>
<
template
#renderItem=
"{ item }"
>
<a-list-item>
<a-comment
:author=
"item.author"
:content=
"item.content"
:datetime=
"item.datetime"
>
<template
#avatar
>
<a-avatar
/>
</
template
>
<
template
#actions
>
<span
key=
"comment-basic-like"
>
<a-tooltip
title=
"Like"
>
<template
v-if=
"action === 'liked'"
>
<LikeFilled
@
click=
"like"
/>
</
template
>
<
template
v-else
>
<LikeOutlined
@
click=
"like"
/>
</
template
>
</a-tooltip>
<span
style=
"padding-left: 8px; cursor: auto"
>
{{ likes }}
</span>
</span>
<span
key=
"comment-basic-dislike"
>
<a-tooltip
title=
"Dislike"
>
<
template
v-if=
"action === 'disliked'"
>
<DislikeFilled
@
click=
"dislike"
/>
</
template
>
<
template
v-else
>
<DislikeOutlined
@
click=
"dislike"
/>
</
template
>
</a-tooltip>
<span
style=
"padding-left: 8px; cursor: auto"
>
{{ dislikes }}
</span>
</span>
<span
key=
"comment-basic-reply-to"
>
Reply to
</span>
</template>
</a-comment>
</a-list-item>
</template>
</a-list>
</a-card>
</template>
<
style
scoped
>
.article-header
{
display
:
flex
;
align-items
:
center
;
}
.article-header
>
:nth-child
(
2
)
{
margin-left
:
10px
;
}
.username
{
font-size
:
1.333rem
;
font-weight
:
500
;
line-height
:
2rem
;
}
</
style
>
src/views/HomeView.vue
浏览文件 @
e124e670
<
script
setup
>
<
script
setup
>
import
{
ref
,
computed
}
from
"
vue
"
;
import
{
ref
,
computed
,
reactive
}
from
"
vue
"
;
import
{
useRoute
,
useRouter
}
from
"
vue-router
"
;
import
{
useRoute
,
useRouter
}
from
"
vue-router
"
;
import
Nav
from
"
../components/nav/index.vue
"
;
import
Nav
from
"
../components/nav/index.vue
"
;
import
{
mockData
}
from
"
@/utils/mockData.js
"
;
import
{
mockData
}
from
"
@/utils/mockData.js
"
;
import
{
useArticleStore
}
from
"
@/stores/article
"
;
import
{
useArticleStore
}
from
"
@/stores/article
"
;
import
{
getStorage
,
setStorage
}
from
"
@/utils/storage
"
;
const
activeKey
=
ref
(
"
1
"
);
const
activeKey
=
ref
(
"
1
"
);
const
router
=
useRouter
();
const
router
=
useRouter
();
const
store
=
useArticleStore
();
const
store
=
useArticleStore
();
const
article
=
store
.
getAllArticle
();
const
articles
=
reactive
([]);
console
.
log
(
article
);
const
atc
=
store
.
getAllArticle
();
if
(
article
)
{
console
.
log
(
articles
);
article
.
forEach
((
item
)
=>
{
if
(
!
atc
)
{
mockData
.
unshift
(
item
);
mockData
.
forEach
((
element
)
=>
{
articles
.
push
(
element
);
});
setStorage
(
"
article
"
,
articles
);
}
else
{
atc
.
forEach
((
element
)
=>
{
articles
.
push
(
element
);
});
});
}
}
const
goToArticle
=
()
=>
{
const
goToArticle
=
()
=>
{
...
@@ -21,6 +28,12 @@
...
@@ -21,6 +28,12 @@
window
.
onresize
=
()
=>
{
window
.
onresize
=
()
=>
{
width
.
value
=
window
.
innerWidth
;
width
.
value
=
window
.
innerWidth
;
};
};
const
viewArticle
=
(
id
)
=>
{
console
.
log
(
id
);
id
.
content
=
JSON
.
stringify
(
id
.
content
);
id
.
comment
=
JSON
.
stringify
(
id
.
comment
);
router
.
push
({
path
:
"
/detailsArticle
"
,
query
:
id
});
};
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -36,8 +49,8 @@
...
@@ -36,8 +49,8 @@
>
>
<a-tab-pane
key=
"1"
tab=
"最新"
>
<a-tab-pane
key=
"1"
tab=
"最新"
>
<a-row
:gutter=
"[,
{ xs: 8, sm: 16, md: 24, lg: 32 }]">
<a-row
:gutter=
"[,
{ xs: 8, sm: 16, md: 24, lg: 32 }]">
<a-col
:span=
"24"
v-for=
"item in
mockData
"
:key=
"item.id"
>
<a-col
:span=
"24"
v-for=
"item in
articles
"
:key=
"item.id"
>
<a-card>
<a-card
@
click=
"viewArticle(item)"
>
<div
class=
"content"
>
<div
class=
"content"
>
<a-avatar
size=
"large"
v-if=
"width > 750"
>
</a-avatar>
<a-avatar
size=
"large"
v-if=
"width > 750"
>
</a-avatar>
<div>
<div>
...
...
src/views/NewArticle.vue
浏览文件 @
e124e670
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
import
{
Editor
,
Toolbar
}
from
"
@wangeditor/editor-for-vue
"
;
import
{
Editor
,
Toolbar
}
from
"
@wangeditor/editor-for-vue
"
;
import
{
useArticleStore
}
from
"
@/stores/article.js
"
;
import
{
useArticleStore
}
from
"
@/stores/article.js
"
;
import
{
useUserStore
}
from
"
@/stores/user.js
"
;
import
{
useUserStore
}
from
"
@/stores/user.js
"
;
import
{
nanoid
}
from
"
nanoid
"
;
import
{
setStorage
,
getStorage
}
from
"
@/utils/storage.js
"
;
const
nano
=
nanoid
();
const
title
=
ref
();
const
title
=
ref
();
// 编辑器实例,必须用 shallowRef
// 编辑器实例,必须用 shallowRef
const
editorRef
=
shallowRef
();
const
editorRef
=
shallowRef
();
...
@@ -16,6 +20,35 @@
...
@@ -16,6 +20,35 @@
const
toolbarConfig
=
{};
const
toolbarConfig
=
{};
const
editorConfig
=
{
const
editorConfig
=
{
placeholder
:
"
请输入内容...
"
,
placeholder
:
"
请输入内容...
"
,
MENU_CONF
:
{
uploadImage
:
{
server
:
"
/api/upload
"
,
base64LimitSize
:
5
*
1024
,
async
customUpload
(
file
,
insertFn
)
{
console
.
log
(
file
);
const
blob
=
new
Blob
([
file
]);
let
reader
=
new
FileReader
();
reader
.
readAsDataURL
(
blob
);
reader
.
onload
=
()
=>
{
console
.
log
(
"
reader
"
,
reader
.
result
);
insertFn
(
reader
.
result
,
"
image
"
,
"
href
"
);
};
},
},
uploadVideo
:
{
server
:
"
/api/upload
"
,
async
customUpload
(
file
,
insertFn
)
{
console
.
log
(
file
);
const
blob
=
new
Blob
([
file
]);
const
reader
=
new
FileReader
();
reader
.
readAsDataURL
(
blob
);
reader
.
onload
=
()
=>
{
console
.
log
(
"
reader
"
,
reader
.
result
);
insertFn
(
reader
.
result
,
"
video
"
);
};
},
},
},
};
};
// 组件销毁时,也及时销毁编辑器
// 组件销毁时,也及时销毁编辑器
...
@@ -31,7 +64,7 @@
...
@@ -31,7 +64,7 @@
const
handleChange
=
(
editor
)
=>
{
const
handleChange
=
(
editor
)
=>
{
const
html
=
editor
.
getHtml
();
const
html
=
editor
.
getHtml
();
valueText
.
value
=
editor
.
getText
();
valueText
.
value
=
editor
.
getText
();
console
.
log
(
html
);
console
.
log
(
html
,
valueText
.
value
);
};
};
const
mode
=
"
deafult
"
;
const
mode
=
"
deafult
"
;
const
store
=
useArticleStore
();
const
store
=
useArticleStore
();
...
@@ -40,7 +73,7 @@
...
@@ -40,7 +73,7 @@
const
router
=
useRouter
();
const
router
=
useRouter
();
const
publishArticle
=
()
=>
{
const
publishArticle
=
()
=>
{
const
data
=
{
const
data
=
{
id
:
Math
.
floor
(
Math
.
random
()
*
Math
.
floor
(
Math
.
random
()))
,
id
:
nano
,
username
:
user
.
username
,
username
:
user
.
username
,
date
:
new
Date
().
toLocaleString
(),
date
:
new
Date
().
toLocaleString
(),
content
:
{
content
:
{
...
@@ -48,9 +81,10 @@
...
@@ -48,9 +81,10 @@
abstract
:
valueText
.
value
,
abstract
:
valueText
.
value
,
article
:
valueHtml
.
value
,
article
:
valueHtml
.
value
,
},
},
comment
:
[],
};
};
console
.
log
(
data
);
console
.
log
(
data
);
store
.
setArticle
(
4
,
data
);
store
.
addAtricle
(
data
);
console
.
log
(
store
.
articles
);
console
.
log
(
store
.
articles
);
router
.
push
(
"
/
"
);
router
.
push
(
"
/
"
);
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录