notice.vue 11 KB

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