messageList.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div class="right">
  3. <div class="up">
  4. <div>
  5. <div class="up-title"><i class="el-icon-search"></i>筛选搜索</div>
  6. <div class="btn">
  7. <el-button plain @click="empty">重置</el-button>
  8. <el-button type="primary" plain @click="check">查询列表</el-button>
  9. </div>
  10. </div>
  11. <div class="left-up">
  12. <div class="up-input-title">
  13. 消息标题:<el-input v-model="input.value1" class="up-input" placeholder="请输入内容"></el-input>
  14. </div>
  15. <div class="up-input-title-right">
  16. <span class="demonstration">发布时间:</span>
  17. <el-date-picker v-model="input.value2" type="datetimerange" class="up-input-right" range-separator="至"
  18. start-placeholder="开始日期" end-placeholder="结束日期" align="right">
  19. </el-date-picker>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="down">
  24. <div class="down-add">
  25. <el-row :gutter="24">
  26. <el-col :span="22" class="down-title"> <i class="el-icon-tickets">消息列表</i> </el-col>
  27. <el-col :span="2"> <el-button id="addBtn" size="small" @click="addNoticce">添加</el-button> </el-col>
  28. </el-row>
  29. </div>
  30. <div class="down-table">
  31. <el-table :data="tableData" order style="width: 100%" class="messagetable">
  32. <el-table-column prop="newsId" label="ID" align="center">
  33. </el-table-column>
  34. <el-table-column :formatter="stateFormat" prop="newsTitle" label="消息标题" align="center">
  35. </el-table-column>
  36. <el-table-column prop="createTime" label="发布时间" align="center">
  37. </el-table-column>
  38. <el-table-column prop="operate" label="操作" align="center">
  39. <template slot-scope="scope">
  40. <el-button size="mini" type="text" @click="viewDetails(scope.row)">查看详情</el-button>
  41. <el-popconfirm title="你确定删除本条消息吗?" @confirm="deleteM(scope.row)">
  42. <el-button class="btn-delete" size="mini" type="text" icon="el-icon-delete"
  43. slot="reference">删除</el-button>
  44. </el-popconfirm>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { getMessage, searchMessage, deleteMessage } from '../../api/message/message'
  54. export default {
  55. data() {
  56. return {
  57. tableData: [], // 数据内容
  58. total: 1, // 数据个数
  59. input: {
  60. value1: '', // 搜索姓名
  61. value2: '' // 搜索时间
  62. }
  63. }
  64. },
  65. mounted() {
  66. this.getMessageList();
  67. },
  68. methods: {
  69. // 获取消息列表
  70. getMessageList() {
  71. getMessage().then((res) => {
  72. this.tableData = res.rows;
  73. this.total = res.total;
  74. })
  75. },
  76. // 搜索消息
  77. check() {
  78. if (this.input.value1 || this.input.value2) {
  79. let searchCon = {
  80. newsTitle: this.input.value1,
  81. // createTime: this.input.value2
  82. }
  83. searchMessage(searchCon).then((res) => {
  84. this.tableData = res.rows;
  85. this.total = res.total;
  86. })
  87. } else {
  88. this.getMessageList();
  89. }
  90. },
  91. // 重置搜索
  92. empty() {
  93. this.input.value1 = "";
  94. this.input.value2 = "";
  95. this.getMessageList();
  96. },
  97. // 删除列表
  98. deleteM(row) {
  99. deleteMessage(row.newsId).then(() => {
  100. this.getMessageList();
  101. })
  102. },
  103. // 查看详情
  104. viewDetails(row) {
  105. console.log(row);
  106. this.$router.push({
  107. name: "messageDetails",
  108. query: {
  109. publishTime: row.createTime,
  110. title: row.newsTitle,
  111. content: row.newsContent
  112. }
  113. });
  114. },
  115. //添加跳转
  116. addNoticce() {
  117. this.$router.push("/messageList/addMessage");
  118. },
  119. // 标题省略
  120. stateFormat(row, column, cellValue) {
  121. if (!cellValue) return ''
  122. if (cellValue.length > 15) { //最长固定显示10个字符
  123. return cellValue.slice(0, 15) + '...'
  124. }
  125. return cellValue
  126. },
  127. }
  128. }
  129. </script>
  130. <style scoped>
  131. .up {
  132. width: 96%;
  133. height: 170px;
  134. margin-top: 20px;
  135. margin-left: 2%;
  136. border: 1px solid #ccc;
  137. border-radius: 4px;
  138. }
  139. .up-title {
  140. font-size: 20px;
  141. width: 20%;
  142. margin-left: 20px;
  143. margin-top: 20px;
  144. float: left;
  145. }
  146. .btn {
  147. float: right;
  148. padding-right: 3%;
  149. margin-top: 2.5%;
  150. }
  151. .up-input {
  152. width: 250px;
  153. margin-left: 15px;
  154. }
  155. .up-input-title {
  156. margin-left: 40px;
  157. float: left;
  158. }
  159. .up-input-right {
  160. margin-left: 15px;
  161. width: 500px;
  162. }
  163. .up-input-title-right {
  164. width: 800px;
  165. margin-left: 450px;
  166. }
  167. .left-up {
  168. width: 80%;
  169. float: left;
  170. height: 37px;
  171. margin-top: 50px;
  172. }
  173. .right-up {
  174. width: 16%;
  175. margin-top: 2%;
  176. float: right;
  177. }
  178. .anniu {
  179. padding-right: 5%;
  180. }
  181. .down {
  182. margin-top: 40px;
  183. }
  184. .down-add {
  185. padding: 10px;
  186. margin: 0 27px;
  187. border: 1px solid #ccc;
  188. border-radius: 2px
  189. }
  190. .down-title {
  191. padding-top: 10px;
  192. color: #303133;
  193. }
  194. .down-table {
  195. margin-top: 15px;
  196. text-align: center;
  197. margin: 35px 27px;
  198. }
  199. .el-table .el-table__header-wrapper th,
  200. .el-table .el-table__fixed-header-wrapper th {
  201. word-break: break-word;
  202. /* background-color: #f8f8f9; */
  203. color: #515a6e;
  204. height: 40px;
  205. font-size: 13px;
  206. text-align: center;
  207. }
  208. .bottom-number {
  209. padding-top: 5px;
  210. color: #303133;
  211. float: right;
  212. }
  213. .bottom-page {
  214. float: right;
  215. }
  216. .el-icon-search {
  217. padding-right: 10px;
  218. }
  219. .btn-delete {
  220. margin-left: 20px;
  221. }
  222. /**
  223. 自适应
  224. */
  225. /* .demonstration{
  226. width: 50%;
  227. } */
  228. .right {
  229. float: none;
  230. width: 100%;
  231. height: 100%;
  232. /* background-color: #9dc3e6; */
  233. }
  234. .bottom {
  235. float: right;
  236. }
  237. </style>