NewsType4.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <!-- 在线问答 -->
  3. <div>
  4. <div style="width: 1200px;padding: 20px;margin: 0 auto;">
  5. <a-breadcrumb>
  6. <a-breadcrumb-item><a href="/index">首页</a></a-breadcrumb-item>
  7. <a-breadcrumb-item>在线问答</a-breadcrumb-item>
  8. </a-breadcrumb>
  9. </div>
  10. <div class="CompanyNews">
  11. <div class="title">
  12. <div class="title-text">我要提问</div>
  13. <div class="title-text2">
  14. <a-textarea style="height:120px" v-model:value="value2" placeholder="请输入问题" allow-clear />
  15. </div>
  16. <div class="title-text3">
  17. <a-button type="primary" @click="submit">提交</a-button>
  18. </div>
  19. </div>
  20. <div class="right">
  21. <div class="right_top">
  22. <a-menu v-model:selectedKeys="rightCurrent" mode="horizontal" :items="rightTopItems" />
  23. </div>
  24. <div class="newsBox">
  25. <div @click="openModal(item)" class="news" v-for="item in list" :key="item.id">
  26. <div class="news_two">
  27. <div class="news_title">
  28. <MessageFilled style="color:#427eff;margin-right:5px" />
  29. {{ item.title }}
  30. </div>
  31. <div class="news_time">{{ item.time }}</div>
  32. <div class="news_text">{{item.outline}}</div>
  33. <div class="news_text2">{{item.views}}个浏览</div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="pagination">
  38. <a-pagination v-model:current="pagecurrent" :pageSize='pageSize' :total="total" />
  39. </div>
  40. </div>
  41. <div>
  42. <a-modal :maskClosable='false' :width='600' :footer="null" v-model:open="open" :title="ModalData.title" @cancel="handleCancel" @ok="handleOk" :centered="true">
  43. <div>
  44. <CommentList :CommentId="CommentId" />
  45. </div>
  46. </a-modal>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <script setup>
  52. import {onMounted,ref,reactive,watch} from 'vue'
  53. import { MessageFilled } from "@ant-design/icons-vue";
  54. import {createQuestion,contentPage,topicDetail,topicReply} from '@/http/api/common.js'
  55. import {openMessage} from '@/views/util/util.js'
  56. import CommentList from './base/comment-list.vue'
  57. const ModalData =ref({
  58. title:''
  59. })
  60. const open =ref(false)
  61. const rightTopItems = ref([
  62. {
  63. label: '热门回答',
  64. title: '热门回答',
  65. key:'1'
  66. },
  67. {
  68. label:'最新回答',
  69. title:'最新回答',
  70. key:'2'
  71. },
  72. {
  73. label:'待回答',
  74. title:'待回答',
  75. key:'3'
  76. }
  77. ]);
  78. const rightCurrent = ref(['1']);
  79. const list = ref([])
  80. const pagecurrent = ref(1)
  81. const pageSize = ref(10)
  82. const total = ref(0)
  83. const value2 = ref('')
  84. const handleCancel = () => {
  85. open.value = false
  86. };
  87. const handleOk = e => {
  88. open.value = false
  89. };
  90. const CommentId = ref('')
  91. const openModal = async (item) =>{
  92. ModalData.value = item
  93. open.value = true
  94. CommentId.value = item.id
  95. }
  96. onMounted(async() => {
  97. //获取所有问题
  98. await getcontentPage()
  99. });
  100. watch(rightCurrent, async() => {
  101. pagecurrent.value = 1
  102. await getcontentPage()
  103. });
  104. watch(pagecurrent, async() => {
  105. await getcontentPage()
  106. });
  107. const getcontentPage =async () =>{
  108. //1=热门回答;2=最新回答;3=带解答?暂时改成我的提问
  109. let data = {
  110. "pageSize": pageSize.value,
  111. "pageNum": pagecurrent.value,
  112. "sortType":rightCurrent.value[0]
  113. }
  114. let res = await contentPage(rightCurrent.value[0],data)
  115. list.value = res.data.rows
  116. total.value = res.data.total
  117. }
  118. async function submit (){
  119. if (!localStorage.getItem('token') || localStorage.getItem('token')=='') {
  120. openMessage('请先登录!')
  121. return
  122. }
  123. if (value2.value == '') {
  124. openMessage('请输入问题')
  125. return
  126. }
  127. //创建问题
  128. let res = await createQuestion({
  129. "title": value2.value,
  130. "content": value2.value
  131. })
  132. if (res.code == 200) {
  133. await getcontentPage()
  134. openMessage('操作成功')
  135. value2.value=''
  136. }else{
  137. openMessage('token已过期 请重新登陆!')
  138. setTimeout(()=>{
  139. localStorage.setItem('token','')
  140. localStorage.setItem('userName','')
  141. window.location.reload()
  142. },1000)
  143. }
  144. }
  145. </script>
  146. <style scoped>
  147. .CompanyNews{
  148. width: 1200px;
  149. margin: 0 auto;
  150. padding: 20px;
  151. min-height: 300px;
  152. background-color: #fff;
  153. }
  154. .title{
  155. display: flex;
  156. flex-direction: column;
  157. }
  158. .title-text {
  159. margin: 20px 0 10px 0;
  160. font-size: 20px;
  161. font-weight: bolder;
  162. width: 100%;
  163. padding-left: 10px;
  164. }
  165. .title-text2 {
  166. width: 100%;
  167. min-height: 130px;
  168. font-size: 18px;
  169. padding: 10px;
  170. }
  171. .title-text3 {
  172. float: right;
  173. width: 100%;
  174. display: flex;
  175. justify-content: flex-end;
  176. padding-right: 10px;
  177. }
  178. .newsBox{
  179. width: 100%;
  180. display: flex;
  181. flex-direction: column;
  182. padding-top: 20px;
  183. }
  184. .news{
  185. width: 100%;
  186. min-width: 350px;
  187. height: 160px;
  188. display: flex;
  189. flex-direction: row;
  190. align-items: center;
  191. margin: 10px;
  192. border-radius: 10px;
  193. padding: 10px 20px;
  194. /* background-color: #f2f2f2; */
  195. border: 1px solid #f2f2f2;
  196. cursor: pointer;
  197. }
  198. .news_title{
  199. font-size: 16px;
  200. font-weight: bold;
  201. }
  202. .news_text{
  203. overflow: hidden;
  204. text-overflow: ellipsis;
  205. white-space: revert-layer;
  206. min-width: 250px;
  207. width: 100%;
  208. min-height: 50px;
  209. line-height: 50px;
  210. text-indent: 1.6rem;
  211. }
  212. .news_text2{
  213. color: #8f8f8f;
  214. text-indent: 1.6rem;
  215. }
  216. .icon{
  217. color: #1677ff;
  218. font-size: 30px;
  219. }
  220. .title_line{
  221. height: 100px;
  222. /* border-left: 1px solid #ccc; */
  223. margin: 0 10px;
  224. }
  225. .news_one{
  226. width: 20%;
  227. min-width: 80px;
  228. height: 100%;
  229. }
  230. .news_one_img{
  231. width: 100%;
  232. min-width: 80px;
  233. height: 100%;
  234. }
  235. .news_two{
  236. width: 100%;
  237. min-width: 250px;
  238. }
  239. .news_time{
  240. color: #999;
  241. }
  242. .pagination{
  243. text-align: center;
  244. margin-top: 20px;
  245. }
  246. </style>