notice.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div style="width: 100%">
  3. <el-main>
  4. <div class="tou">通知公告</div>
  5. <div>
  6. <el-button
  7. size="small"
  8. type="primary"
  9. style="position: absolute; right: 20px; top: 90px"
  10. @click="dialogVisible1 = true"
  11. >新建全站通知</el-button
  12. >
  13. <!-- <div>Banner管理</div> -->
  14. <el-table
  15. ref="table"
  16. :data="tableData"
  17. stripe
  18. border
  19. :header-cell-style="{ background: '#f1f1f1', 'text-align': 'center' }"
  20. :cell-style="{ 'text-align': 'center' }"
  21. style="width: 100%; margin-top: 70px"
  22. :height="tableHeight"
  23. v-loading="isLoading"
  24. >
  25. <el-table-column prop="title" label="通知标题" min-width="15">
  26. </el-table-column>
  27. <el-table-column
  28. prop="newscontent"
  29. label="通知内容"
  30. min-width="60"
  31. :show-overflow-tooltip="true"
  32. >
  33. <template slot-scope="scope">
  34. <div
  35. v-html="snippet(scope.row.content)"
  36. class="DivOverflow"
  37. ></div>
  38. <div></div>
  39. </template>
  40. </el-table-column>
  41. <el-table-column prop="creatTime" label="创建时间" min-width="20">
  42. </el-table-column>
  43. <el-table-column prop="do" label="操作" min-width="20">
  44. <template slot-scope="scope">
  45. <div class="pb_buttonBox">
  46. <el-button
  47. size="mini"
  48. type="primary"
  49. @click="getNoticeDetail(scope.row)"
  50. >查看详情</el-button
  51. >
  52. <el-button
  53. size="mini"
  54. type="primary"
  55. @click="deleteNotice(scope.row.newsid)"
  56. >删除</el-button
  57. >
  58. </div>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. </div>
  63. <div class="student_page">
  64. <el-pagination
  65. background
  66. layout="prev, pager, next"
  67. :page-size="10"
  68. :total="total"
  69. @current-change="handleCurrentChange"
  70. >
  71. </el-pagination>
  72. </div>
  73. </el-main>
  74. <el-dialog
  75. title="添加全站通知"
  76. :visible.sync="dialogVisible1"
  77. width="550px"
  78. :before-close="handleClose"
  79. class="dialog_diy"
  80. center
  81. >
  82. <div>
  83. <div class="tian1">
  84. <span>通知标题</span>
  85. <el-input
  86. v-model="noticeTitle"
  87. style="width: 250px; margin: 15px 0px"
  88. placeholder="请输入通知标题"
  89. ></el-input>
  90. </div>
  91. <div class="tian1">
  92. <span>通知内容</span>
  93. <editor-bar
  94. v-model="detail"
  95. :isClear="isClear"
  96. @change="change"
  97. ></editor-bar>
  98. </div>
  99. </div>
  100. <span slot="footer" class="dialog-footer">
  101. <el-button type="primary" @click="addNotice">确认通知</el-button>
  102. <el-button @click="dialogVisible1 = false">取 消</el-button>
  103. </span>
  104. </el-dialog>
  105. <el-dialog
  106. title="查看通知"
  107. :visible.sync="dialogVisible2"
  108. width="60%"
  109. :before-close="handleClose"
  110. class="dialog_diy dialog_diyA"
  111. center
  112. >
  113. <div class="head">
  114. <span>{{ NoticeDeatail.title }}</span>
  115. <span class="name">{{ NoticeDeatail.creatTime }}</span>
  116. </div>
  117. <div class="cont" v-html="NoticeDeatail.content"></div>
  118. <span slot="footer" class="dialog-footer">
  119. <el-button type="primary" @click="dialogVisible2 = false"
  120. >关闭</el-button
  121. >
  122. </span>
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script>
  127. import EditorBar from "../../components/tools/wangEnduit";
  128. export default {
  129. components: { EditorBar },
  130. data() {
  131. return {
  132. noticeTitle: "",
  133. isClear: false,
  134. detail: "",
  135. dialogVisible1: false,
  136. dialogVisible2: false,
  137. tableData: [],
  138. isLoading: false,
  139. total: 0,
  140. page: 1,
  141. tableHeight: 500,
  142. NoticeDeatail: {},
  143. };
  144. },
  145. methods: {
  146. //在method里面写方法
  147. snippet(value) {
  148. return value.replace(/<[^>]*>/g, "");
  149. },
  150. time() {
  151. if (!this.now) {
  152. this.now = new Date().getTime();
  153. return true;
  154. } else {
  155. let time = new Date().getTime();
  156. if (time - this.now > 3000) {
  157. this.now = time;
  158. return true;
  159. } else {
  160. return false;
  161. }
  162. }
  163. },
  164. changeHeight() {
  165. this.tableHeight =
  166. window.innerHeight - this.$refs.table.$el.offsetTop - 200;
  167. if (this.tableHeight <= 530) {
  168. this.tableHeight = 530;
  169. }
  170. // 监听窗口大小变化
  171. let self = this;
  172. window.onresize = function () {
  173. self.tableHeight =
  174. window.innerHeight - self.$refs.table.$el.offsetTop - 200;
  175. if (self.tableHeight <= 530) {
  176. self.tableHeight = 530;
  177. }
  178. };
  179. // this.$refs.table.$el.offsetTop:表格距离浏览器的高度 //200表示你想要调整的表格距离底部的高度(你可以自己随意调整),因为我们一般都有放分页组件的,所以需要给它留一个高度
  180. },
  181. handleClose(done) {
  182. done();
  183. },
  184. change(val) {
  185. console.log(val);
  186. },
  187. handleCurrentChange(val) {
  188. // console.log(`当前页: ${val}`);
  189. this.page = val;
  190. this.getNotice();
  191. },
  192. //获取通知
  193. getNotice() {
  194. this.isLoading = true;
  195. let params = { uid: "0", page: this.page };
  196. this.ajax
  197. .get(this.$store.state.api + "getNewsTeacher", params)
  198. .then((res) => {
  199. this.isLoading = false;
  200. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  201. this.tableData = res.data[0];
  202. console.log(this.tableData);
  203. })
  204. .catch((err) => {
  205. this.isLoading = false;
  206. console.error(err);
  207. });
  208. },
  209. init() {
  210. this.detail = "";
  211. this.noticeTitle = "";
  212. },
  213. //添加通知
  214. addNotice() {
  215. if (this.noticeTitle === "") {
  216. this.$message.error("请输入文章标题");
  217. return;
  218. } else if (this.detail === "") {
  219. this.$message.error("请输入文章内容");
  220. return;
  221. }
  222. console.log(this.detail);
  223. if (this.time()) {
  224. let params = [
  225. {
  226. t: this.noticeTitle,
  227. nc: this.detail.replace(/%/g, "%25"),
  228. s: 0,
  229. r: 0,
  230. },
  231. ];
  232. this.ajax
  233. .post(this.$store.state.api + "addNews", params)
  234. .then((res) => {
  235. this.$message({
  236. message: "添加成功",
  237. type: "success",
  238. });
  239. this.init();
  240. this.getNotice();
  241. this.dialogVisible1 = false;
  242. })
  243. .catch((err) => {
  244. this.$message.error("添加失败");
  245. console.error(err);
  246. });
  247. }
  248. },
  249. //删除通知
  250. deleteNotice(id) {
  251. let params = [{ nid: id }];
  252. this.$confirm("确定删除此通知吗?", "提示", {
  253. confirmButtonText: "确定",
  254. cancelButtonText: "取消",
  255. type: "warning",
  256. })
  257. .then(() => {
  258. this.ajax
  259. .post(this.$store.state.api + "deleteNews", params)
  260. .then((res) => {
  261. this.$message({
  262. message: "删除成功",
  263. type: "success",
  264. });
  265. if (this.page != 1 && this.tableData.length == 1) {
  266. this.page--;
  267. }
  268. this.getNotice();
  269. })
  270. .catch((err) => {
  271. this.$message.error("删除失败");
  272. console.error(err);
  273. });
  274. })
  275. .catch(() => {});
  276. },
  277. getNoticeDetail(res) {
  278. this.dialogVisible2 = true;
  279. this.NoticeDeatail = res;
  280. },
  281. },
  282. created() {
  283. this.$nextTick(function () {
  284. this.page = 1;
  285. this.getNotice();
  286. this.changeHeight();
  287. });
  288. },
  289. };
  290. </script>
  291. <style scoped>
  292. .DivOverflow {
  293. overflow: hidden;
  294. text-overflow: ellipsis;
  295. }
  296. .tou {
  297. border-bottom: 1px solid #c9c9c9;
  298. height: 50px;
  299. font-size: 30px;
  300. }
  301. .tian1 {
  302. margin-top: 15px;
  303. }
  304. .tian1 span {
  305. display: block;
  306. }
  307. .head {
  308. margin: 0 0 15px;
  309. font-size: 20px;
  310. border-bottom: 1px solid;
  311. /* height: 35px; */
  312. display: flex;
  313. align-items: center;
  314. padding-bottom: 10px;
  315. justify-content: space-between;
  316. align-items: flex-end;
  317. }
  318. .name {
  319. /* margin-top: -30px; */
  320. font-size: 14px;
  321. }
  322. .cont {
  323. font-size: 16px;
  324. line-height: 34px;
  325. text-indent: 2em;
  326. }
  327. .dialog_diy >>> .el-dialog__header {
  328. background: #3d67bc !important;
  329. padding: 15px 20px;
  330. }
  331. .dialog_diy >>> .el-dialog__title {
  332. color: #fff;
  333. }
  334. .dialog_diy >>> .el-dialog__headerbtn {
  335. top: 19px;
  336. }
  337. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  338. color: #fff;
  339. }
  340. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  341. color: #fff;
  342. }
  343. .student_page {
  344. margin-top: 15px;
  345. }
  346. .dialog_diyA >>> .el-dialog {
  347. min-width: 600px;
  348. }
  349. .dialog_diyA >>> .el-dialog__body {
  350. max-height: 750px;
  351. overflow: auto;
  352. }
  353. /* table 样式 */
  354. .cont >>> table {
  355. border-top: 1px solid #ccc;
  356. border-left: 1px solid #ccc;
  357. }
  358. .cont >>> table td,
  359. .cont >>> table th {
  360. border-bottom: 1px solid #ccc;
  361. border-right: 1px solid #ccc;
  362. padding: 3px 5px;
  363. }
  364. .cont >>> table th {
  365. border-bottom: 2px solid #ccc;
  366. text-align: center;
  367. }
  368. /* blockquote 样式 */
  369. .cont >>> blockquote {
  370. display: block;
  371. border-left: 8px solid #d0e5f2;
  372. padding: 5px 10px;
  373. margin: 10px 0;
  374. line-height: 1.4;
  375. font-size: 100%;
  376. background-color: #f1f1f1;
  377. }
  378. /* code 样式 */
  379. .cont >>> code {
  380. display: inline-block;
  381. *display: inline;
  382. *zoom: 1;
  383. background-color: #f1f1f1;
  384. border-radius: 3px;
  385. padding: 3px 5px;
  386. margin: 0 3px;
  387. }
  388. .cont >>> pre code {
  389. display: block;
  390. }
  391. /* ul ol 样式 */
  392. .cont >>> ul,
  393. ol {
  394. margin: 10px 0 10px 20px;
  395. }
  396. </style>