index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div class="message">
  3. <div class="conten">
  4. <h2 class="title">留 言 板</h2>
  5. <ul class="liuyan" v-if="data.length > 0">
  6. <li v-for="item in data" :key="item.id">
  7. <div class="name">{{ item.creatorName }}</div>
  8. <div class="con">{{ item.content }}</div>
  9. <div class="time">{{ item.createTime }}</div>
  10. </li>
  11. </ul>
  12. <!-- 没有数据的时候提示 -->
  13. <div class="liuyan noneTxt" v-else>暂无数据</div>
  14. <!-- 分页器 -->
  15. <div class="pagination">
  16. <el-pagination
  17. layout="prev, pager, next"
  18. :total="total"
  19. @current-change="currentChange"
  20. >
  21. </el-pagination>
  22. </div>
  23. <!-- 文本域和按钮 -->
  24. <div class="bottmInp">
  25. <div class="texe">
  26. <el-input
  27. maxlength="100"
  28. show-word-limit
  29. resize="none"
  30. type="textarea"
  31. :rows="3"
  32. placeholder="欢迎提交您的珍贵留言,100字以内~"
  33. v-model="textarea"
  34. >
  35. </el-input>
  36. </div>
  37. <div class="button">
  38. <div class="button_left">
  39. <div class="biaoji"></div>
  40. <el-input
  41. style="width: 270px"
  42. type="text"
  43. placeholder="请填写您的姓名"
  44. v-model="name"
  45. maxlength="8"
  46. show-word-limit
  47. >
  48. </el-input>
  49. </div>
  50. <el-button
  51. style="width: 120px; color: #d7b07e"
  52. type="primary"
  53. @click="commentSave"
  54. >提 交</el-button
  55. >
  56. </div>
  57. </div>
  58. </div>
  59. <ul>
  60. <li>
  61. <span></span>
  62. </li>
  63. </ul>
  64. </div>
  65. </template>
  66. <script>
  67. import { commentSave, commentWebList } from '@/apis/tab7'
  68. export default {
  69. name: 'message',
  70. components: {},
  71. data () {
  72. // 这里存放数据
  73. return {
  74. textarea: '',
  75. name: '',
  76. data: [],
  77. total: 0,
  78. formData: {
  79. startTime: '',
  80. endTime: '',
  81. pageNum: 1,
  82. pageSize: 10,
  83. searchKey: '',
  84. status: 2
  85. }
  86. }
  87. },
  88. // 监听属性 类似于data概念
  89. computed: {},
  90. // 监控data中的数据变化
  91. watch: {},
  92. // 方法集合
  93. methods: {
  94. // 分页器方法
  95. currentChange (val) {
  96. // console.log('当前页改变了', val)
  97. this.formData.pageNum = val
  98. this.commentWebList(this.formData)
  99. },
  100. // 点击提交留言
  101. async commentSave () {
  102. if (this.textarea.trim() === '') { return this.$message.warning('内容不能为空!') }
  103. if (this.name.trim() === '') { return this.$message.warning('名字不能为空!') }
  104. const res = await commentSave({
  105. content: this.textarea,
  106. creatorName: this.name
  107. })
  108. if (res.code === 0) {
  109. this.textarea = this.name = ''
  110. this.$message.success('提交成功,等待审核.')
  111. } else this.$message.warning(res.msg)
  112. },
  113. // 封装获取列表的方法
  114. async commentWebList (data) {
  115. const res = await commentWebList(data)
  116. this.total = res.data.total
  117. res.data.records.forEach((v) => {
  118. v.createTime = v.createTime.substring(0, v.createTime.length - 3)
  119. })
  120. this.data = res.data.records
  121. }
  122. },
  123. // 生命周期 - 创建完成(可以访问当前this实例)
  124. created () {
  125. this.commentWebList(this.formData)
  126. },
  127. // 生命周期 - 挂载完成(可以访问DOM元素)
  128. mounted () {},
  129. beforeCreate () {}, // 生命周期 - 创建之前
  130. beforeMount () {}, // 生命周期 - 挂载之前
  131. beforeUpdate () {}, // 生命周期 - 更新之前
  132. updated () {}, // 生命周期 - 更新之后
  133. beforeDestroy () {}, // 生命周期 - 销毁之前
  134. destroyed () {}, // 生命周期 - 销毁完成
  135. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  136. }
  137. </script>
  138. <style lang='less' scoped>
  139. /deep/.el-input__inner::-webkit-input-placeholder {
  140. color: #878787 !important;
  141. }
  142. /deep/.el-input__inner:-moz-placeholder {
  143. color: #878787 !important;
  144. }
  145. /deep/.el-input__inner::-moz-placeholder {
  146. color: #878787 !important;
  147. }
  148. /deep/.el-input__inner:-ms-input-placeholder {
  149. /* Internet Explorer 10+ */
  150. color: #878787 !important;
  151. }
  152. /deep/.el-textarea__inner::-webkit-input-placeholder {
  153. color: #878787 !important;
  154. }
  155. /deep/.el-textarea__inner:-moz-placeholder {
  156. color: #878787 !important;
  157. }
  158. /deep/.el-textarea__inner::-moz-placeholder {
  159. color: #878787 !important;
  160. }
  161. /deep/.el-textarea__inner:-ms-input-placeholder {
  162. /* Internet Explorer 10+ */
  163. color: #878787 !important;
  164. }
  165. .message {
  166. position: relative;
  167. margin: 0 auto;
  168. width: 1000px;
  169. height: 100vh;
  170. min-height: 650px;
  171. .conten {
  172. background: url("../../assets/img/mesBac.png");
  173. background-size: 100% 100%;
  174. border-top: 8px solid #be1220;
  175. border-bottom: 8px solid #be1220;
  176. /deep/.el-button--primary {
  177. background-color: #b92e2e;
  178. width: 100%;
  179. height: 40px;
  180. }
  181. /deep/.el-pager li {
  182. background-color: transparent;
  183. color: #333333;
  184. }
  185. /deep/.el-pager li.active {
  186. color: #b92e2e;
  187. }
  188. /deep/.el-pagination button {
  189. background-color: transparent;
  190. }
  191. /deep/.el-pagination button:disabled {
  192. background-color: transparent;
  193. }
  194. position: absolute;
  195. top: 50%;
  196. left: 0;
  197. transform: translateY(-50%);
  198. width: 100%;
  199. height: 650px;
  200. background-color: #fff;
  201. padding: 20px;
  202. .title {
  203. padding-left: 20px;
  204. color: #fff;
  205. }
  206. .liuyan::-webkit-scrollbar {
  207. /*滚动条整体样式*/
  208. width: 3px; /*高宽分别对应横竖滚动条的尺寸*/
  209. height: 1px;
  210. }
  211. .liuyan::-webkit-scrollbar-thumb {
  212. /*滚动条里面小方块*/
  213. border-radius: 10px;
  214. box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  215. background: rgba(185, 46, 46, 0.3);
  216. }
  217. .liuyan::-webkit-scrollbar-track {
  218. /*滚动条里面轨道*/
  219. // box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  220. border-radius: 10px;
  221. background: transparent;
  222. }
  223. .liuyan {
  224. background-color: rgba(255, 255, 255, 0.3);
  225. padding-right: 20px;
  226. margin: 20px 20px 0;
  227. padding: 15px;
  228. height: 320px;
  229. overflow-y: auto;
  230. li {
  231. border-bottom: 1px dashed #b92e2e;
  232. color: #878787;
  233. font-size: 16px;
  234. display: flex;
  235. & > div {
  236. padding: 12px 0;
  237. }
  238. .name {
  239. width: 140px;
  240. }
  241. .con {
  242. flex: 1;
  243. margin-right: 20px;
  244. }
  245. .time {
  246. width: 140px;
  247. }
  248. }
  249. }
  250. .noneTxt {
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. font-size: 26px;
  255. }
  256. .pagination {
  257. padding: 20px;
  258. margin: 0 auto;
  259. width: 920px;
  260. display: flex;
  261. justify-content: center;
  262. align-items: center;
  263. background-color: rgba(255, 255, 255, 0.3);
  264. }
  265. .bottmInp {
  266. /deep/.el-textarea__inner:focus {
  267. border-color: #b9412e;
  268. }
  269. /deep/.el-textarea__inner {
  270. background-color: rgba(255, 255, 255, 0.3);
  271. }
  272. /deep/.el-input__inner {
  273. background-color: rgba(255, 255, 255, 0.3);
  274. }
  275. /deep/.el-textarea .el-input__count {
  276. background-color: transparent;
  277. color: #878787;
  278. }
  279. /deep/.el-input__count-inner {
  280. background-color: transparent;
  281. color: #878787;
  282. }
  283. margin-top: 15px;
  284. width: 100%;
  285. padding: 0 20px;
  286. }
  287. .button {
  288. margin-top: 15px;
  289. display: flex;
  290. justify-content: space-between;
  291. .button_left {
  292. width: 300px;
  293. display: flex;
  294. align-items: center;
  295. .biaoji {
  296. position: relative;
  297. margin-right: 10px;
  298. width: 20px;
  299. height: 20px;
  300. border-radius: 50%;
  301. border: 1px solid #b9412e;
  302. &::after {
  303. content: "";
  304. position: absolute;
  305. top: 50%;
  306. left: 50%;
  307. transform: translate(-50%, -50%);
  308. width: 15px;
  309. height: 15px;
  310. border-radius: 50%;
  311. background-color: #b9412e;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. </style>