messageList.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 height="300" :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="newsTime" 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. <el-pagination @current-change="handleCurrentChange" background layout="total, prev, pager, next" :total="total"
  51. id="page">
  52. </el-pagination>
  53. </div>
  54. </template>
  55. <script>
  56. import { getMessage, searchMessage, deleteMessage } from '../../api/message/message'
  57. export default {
  58. data() {
  59. return {
  60. tableData: [], // 数据内容
  61. total: 1, // 数据个数
  62. input: {
  63. value1: '', // 搜索姓名
  64. value2: '' // 搜索时间
  65. },
  66. pageInfo: { // 分页信息
  67. pageNum: 1,
  68. pageSize: 10
  69. }
  70. }
  71. },
  72. mounted() {
  73. this.getMessageList();
  74. },
  75. methods: {
  76. // 获取消息列表
  77. getMessageList() {
  78. getMessage(this.pageInfo).then((res) => {
  79. this.tableData = res.rows;
  80. this.total = res.total;
  81. })
  82. },
  83. // 分页跳转
  84. handleCurrentChange(newPage) {
  85. this.pageInfo.pageNum = newPage;
  86. this.getMessageList();
  87. },
  88. // 搜索消息
  89. check() {
  90. if (this.input.value1 || this.input.value2) {
  91. let startTime = this.$formatDate(this.input.value2[0], 'yyyy-MM-dd hh:mm:ss');
  92. let endTime = this.$formatDate(this.input.value2[1], 'yyyy-MM-dd hh:mm:ss');
  93. let searchCon = {
  94. newsTitle: this.input.value1,
  95. newsTimeStart: startTime,
  96. newsTimeEnd: endTime
  97. }
  98. searchMessage(searchCon).then((res) => {
  99. this.tableData = res.rows;
  100. this.total = res.total;
  101. })
  102. } else {
  103. this.getMessageList();
  104. }
  105. },
  106. // 重置搜索
  107. empty() {
  108. this.input.value1 = "";
  109. this.input.value2 = "";
  110. this.getMessageList();
  111. },
  112. // 删除列表
  113. deleteM(row) {
  114. this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
  115. confirmButtonText: '确定',
  116. cancelButtonText: '取消',
  117. type: 'warning'
  118. }).then(() => {
  119. deleteMessage(row.newsId).then(() => {
  120. this.getMessageList();
  121. })
  122. this.$message({
  123. type: 'success',
  124. message: '删除成功!'
  125. });
  126. }).catch(() => {
  127. this.$message({
  128. type: 'info',
  129. message: '已取消删除'
  130. });
  131. });
  132. },
  133. // 查看详情
  134. viewDetails(row) {
  135. this.$router.push({
  136. name: "messageDetails",
  137. query: {
  138. publishTime: row.newsTime,
  139. title: row.newsTitle,
  140. content: row.newsContent
  141. }
  142. });
  143. },
  144. // 添加跳转
  145. addNoticce() {
  146. this.$router.push("/messageList/addMessage");
  147. },
  148. // 标题省略
  149. stateFormat(row, column, cellValue) {
  150. if (!cellValue) return ''
  151. if (cellValue.length > 15) { //最长固定显示10个字符
  152. return cellValue.slice(0, 15) + '...'
  153. }
  154. return cellValue
  155. },
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. .up {
  161. width: 96%;
  162. height: 170px;
  163. margin-top: 20px;
  164. margin-left: 2%;
  165. border: 1px solid #ccc;
  166. border-radius: 4px;
  167. }
  168. .up-title {
  169. font-size: 20px;
  170. width: 20%;
  171. margin-left: 20px;
  172. margin-top: 20px;
  173. float: left;
  174. }
  175. .btn {
  176. float: right;
  177. padding-right: 3%;
  178. margin-top: 2.5%;
  179. }
  180. .up-input {
  181. width: 250px;
  182. margin-left: 15px;
  183. }
  184. .up-input-title {
  185. margin-left: 40px;
  186. float: left;
  187. }
  188. .up-input-right {
  189. margin-left: 15px;
  190. width: 500px;
  191. }
  192. .up-input-title-right {
  193. width: 800px;
  194. margin-left: 450px;
  195. }
  196. .left-up {
  197. width: 80%;
  198. float: left;
  199. height: 37px;
  200. margin-top: 50px;
  201. }
  202. .right-up {
  203. width: 16%;
  204. margin-top: 2%;
  205. float: right;
  206. }
  207. .anniu {
  208. padding-right: 5%;
  209. }
  210. .down {
  211. margin-top: 40px;
  212. }
  213. .down-add {
  214. padding: 10px;
  215. margin: 0 27px;
  216. border: 1px solid #ccc;
  217. border-radius: 2px
  218. }
  219. .down-title {
  220. padding-top: 10px;
  221. color: #303133;
  222. }
  223. .down-table {
  224. margin-top: 15px;
  225. text-align: center;
  226. margin: 35px 27px;
  227. }
  228. .el-table .el-table__header-wrapper th,
  229. .el-table .el-table__fixed-header-wrapper th {
  230. word-break: break-word;
  231. /* background-color: #f8f8f9; */
  232. color: #515a6e;
  233. height: 40px;
  234. font-size: 13px;
  235. text-align: center;
  236. }
  237. .bottom-number {
  238. padding-top: 5px;
  239. color: #303133;
  240. float: right;
  241. }
  242. .bottom-page {
  243. float: right;
  244. }
  245. .el-icon-search {
  246. padding-right: 10px;
  247. }
  248. .btn-delete {
  249. margin-left: 20px;
  250. }
  251. /**
  252. 自适应
  253. */
  254. /* .demonstration{
  255. width: 50%;
  256. } */
  257. .right {
  258. float: none;
  259. width: 100%;
  260. height: 100%;
  261. /* background-color: #9dc3e6; */
  262. }
  263. .bottom {
  264. float: right;
  265. }
  266. #page {
  267. float: right;
  268. margin-right: 20px;
  269. }
  270. </style>