find.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <template>
  2. <div style="width: 100%">
  3. <el-main>
  4. <div class="tou">发现管理</div>
  5. <div>
  6. <div class="bbox">
  7. <el-button size="small" type="primary" style="" @click="insertPop"
  8. >添加文章</el-button
  9. >
  10. </div>
  11. <el-table
  12. ref="table"
  13. v-loading="isLoading"
  14. :data="tableData"
  15. stripe
  16. border
  17. :header-cell-style="{ background: '#f1f1f1', 'text-align': 'center' }"
  18. :cell-style="{ 'text-align': 'center' }"
  19. style="width: 100%; margin-top: 15px"
  20. :height="tableHeight"
  21. >
  22. <el-table-column
  23. prop="title"
  24. label="文章标题"
  25. min-width="35"
  26. :show-overflow-tooltip="true"
  27. >
  28. </el-table-column>
  29. <el-table-column prop="time" label="创建时间" min-width="15">
  30. </el-table-column>
  31. <el-table-column prop="do" label="操作" min-width="20">
  32. <template slot-scope="scope">
  33. <div class="pb_buttonBox">
  34. <el-button
  35. size="mini"
  36. type="primary"
  37. @click="getDetail(scope.row.id)"
  38. >查看详情</el-button
  39. >
  40. <el-button
  41. size="mini"
  42. type="primary"
  43. @click="updatePop(scope.row.id, scope.$index)"
  44. >修改</el-button
  45. >
  46. <el-button
  47. size="mini"
  48. type="primary"
  49. @click="deleteFind(scope.row.id)"
  50. >删除</el-button
  51. >
  52. </div>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. </div>
  57. <div class="student_page">
  58. <el-pagination
  59. background
  60. layout="prev, pager, next"
  61. :page-size="10"
  62. :total="total"
  63. @current-change="handleCurrentChange"
  64. >
  65. </el-pagination>
  66. </div>
  67. </el-main>
  68. <el-dialog
  69. title="添加文章"
  70. :visible.sync="dialogVisible1"
  71. width="500px"
  72. :before-close="handleClose"
  73. class="dialog_diyA dialog_diy"
  74. center
  75. >
  76. <div>
  77. <div class="tian1">
  78. <span>标题</span>
  79. <el-input
  80. v-model="contentTitle"
  81. style="width: 250px; margin: 15px 0px"
  82. placeholder="请输入文章标题"
  83. ></el-input>
  84. </div>
  85. <div class="tian1">
  86. <span>文章海报</span>
  87. <!-- :on-success="handle_success" -->
  88. <!-- :before-upload="beforeUpload1" -->
  89. <el-upload
  90. action="#"
  91. list-type="picture"
  92. style="margin: 15px 0px"
  93. v-loading="uploadLoading1"
  94. :http-request="beforeUpload1"
  95. ref="upload1"
  96. :on-preview="handlePictureCardPreview"
  97. :on-remove="handle_remove1"
  98. :show-file-list="true"
  99. accept="image/*"
  100. :file-list="fileList1"
  101. :limit="1"
  102. >
  103. <!-- <i class="el-icon-plus"></i> -->
  104. <el-button size="small" type="primary">点击上传</el-button>
  105. </el-upload>
  106. </div>
  107. <div class="tian1">
  108. <span>文章内容</span>
  109. <!-- <el-input
  110. type="textarea"
  111. rows="10"
  112. v-model="input"
  113. style="width: 100%; margin: 15px 0px"
  114. placeholder="请输入文章内容"
  115. ></el-input> -->
  116. <editor-bar
  117. v-model="detail"
  118. :isClear="isClear"
  119. @change="change"
  120. ></editor-bar>
  121. </div>
  122. </div>
  123. <span slot="footer" class="dialog-footer">
  124. <el-button @click="dialogVisible1 = false">取 消</el-button>
  125. <el-button type="primary" @click="addContent">确 定</el-button>
  126. </span>
  127. </el-dialog>
  128. <el-dialog
  129. title="修改文章"
  130. :visible.sync="dialogVisible3"
  131. width="500px"
  132. :before-close="handleClose"
  133. class="dialog_diyA dialog_diy"
  134. center
  135. >
  136. <div>
  137. <div class="tian1">
  138. <span>标题</span>
  139. <el-input
  140. v-model="updateJson.title"
  141. style="width: 250px; margin: 15px 0px"
  142. placeholder="请输入修改的文章标题"
  143. ></el-input>
  144. </div>
  145. <div class="tian1">
  146. <span>文章海报</span>
  147. <!-- :on-success="handle_success" -->
  148. <!-- :before-upload="beforeUpload1" -->
  149. <el-upload
  150. action="#"
  151. list-type="picture"
  152. style="margin: 15px 0px"
  153. v-loading="uploadLoading1"
  154. :http-request="beforeUpload1"
  155. ref="upload1"
  156. :on-preview="handlePictureCardPreview"
  157. :on-remove="handle_remove1"
  158. :show-file-list="true"
  159. accept="image/*"
  160. :file-list="fileList1"
  161. :limit="1"
  162. >
  163. <!-- <i class="el-icon-plus"></i> -->
  164. <el-button size="small" type="primary">点击上传</el-button>
  165. </el-upload>
  166. </div>
  167. <div class="tian1">
  168. <span>文章内容</span>
  169. <!-- <el-input
  170. type="textarea"
  171. rows="10"
  172. v-model="input"
  173. style="width: 100%; margin: 15px 0px"
  174. placeholder="请输入文章内容"
  175. ></el-input> -->
  176. <editor-bar
  177. v-model="updateJson.content"
  178. :isClear="isClear"
  179. @change="change"
  180. ></editor-bar>
  181. </div>
  182. </div>
  183. <span slot="footer" class="dialog-footer">
  184. <el-button @click="dialogVisible3 = false">取 消</el-button>
  185. <el-button type="primary" @click="updateDetail">确 定</el-button>
  186. </span>
  187. </el-dialog>
  188. <el-dialog
  189. title="查看详情"
  190. :visible.sync="dialogVisible2"
  191. width="50%"
  192. :before-close="handleClose"
  193. class="dialog_diyA dialog_diyH dialog_diy"
  194. height="500px"
  195. center
  196. >
  197. <div>
  198. <div class="head">
  199. <span>{{ homeDeatail.title }}</span>
  200. <span class="name">{{ homeDeatail.time }}</span>
  201. </div>
  202. <div class="cont" v-html="homeDeatail.content"></div>
  203. </div>
  204. <span slot="footer" class="dialog-footer">
  205. <el-button type="primary" @click="dialogVisible2 = false"
  206. >关闭</el-button
  207. >
  208. </span>
  209. </el-dialog>
  210. <el-dialog :visible.sync="ImageVisible1" size="tiny">
  211. <img width="100%" :src="dialogImageUrl" alt="" />
  212. </el-dialog>
  213. </div>
  214. </template>
  215. <script>
  216. import EditorBar from "../../components/tools/wangEnduit";
  217. import "../../common/aws-sdk-2.235.1.min";
  218. export default {
  219. components: { EditorBar },
  220. data() {
  221. return {
  222. isClear: false,
  223. detail: "",
  224. dialogVisible1: false,
  225. dialogVisible2: false,
  226. tableData: [],
  227. uploadLoading1: false,
  228. fileList1: [],
  229. ImageVisible1: false,
  230. dialogImageUrl: "",
  231. now: "",
  232. contentTitle: "",
  233. isLoading: false,
  234. total: 0,
  235. page: 1,
  236. tableHeight: 500,
  237. homeDeatail: [],
  238. updateJson: {},
  239. dialogVisible3: false,
  240. updateId: "",
  241. };
  242. },
  243. methods: {
  244. time() {
  245. if (!this.now) {
  246. this.now = new Date().getTime();
  247. return true;
  248. } else {
  249. let time = new Date().getTime();
  250. if (time - this.now > 3000) {
  251. this.now = time;
  252. return true;
  253. } else {
  254. return false;
  255. }
  256. }
  257. },
  258. init() {
  259. this.detail = "";
  260. this.fileList1 = [];
  261. this.contentTitle = "";
  262. this.updateJson = {};
  263. this.updateId = "";
  264. },
  265. insertPop() {
  266. this.init();
  267. this.dialogVisible1 = true;
  268. },
  269. handlePictureCardPreview(file) {
  270. this.dialogImageUrl = file.url;
  271. this.ImageVisible1 = true;
  272. },
  273. handle_remove1(file, fileList) {
  274. var _tmp = this.fileList1;
  275. for (var i = 0, len = _tmp.length; i < len; i++) {
  276. if (_tmp[i].uid == file.uid) {
  277. _tmp.splice(i, 1);
  278. break;
  279. }
  280. this.fileList1 = _tmp;
  281. }
  282. },
  283. beforeUpload1(data) {
  284. this.$refs.upload1.uploadFiles;
  285. this.uploadLoading1 = true;
  286. var file = data.file;
  287. var credentials = {
  288. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  289. secretAccessKey: "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",
  290. }; //秘钥形式的登录上传
  291. window.AWS.config.update(credentials);
  292. window.AWS.config.region = "cn-northwest-1"; //设置区域
  293. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  294. var _this = this;
  295. if (file) {
  296. var params = {
  297. Key:
  298. file.name.split(".")[0] +
  299. new Date().getTime() +
  300. "." +
  301. file.name.split(".")[1],
  302. ContentType: file.type,
  303. Body: file,
  304. "Access-Control-Allow-Credentials": "*",
  305. ACL: "public-read",
  306. }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  307. var options = {
  308. partSize: 2048 * 1024 * 1024,
  309. queueSize: 2,
  310. leavePartsOnError: true,
  311. };
  312. bucket
  313. .upload(params, options)
  314. .on("httpUploadProgress", function (evt) {
  315. //这里可以写进度条
  316. // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  317. })
  318. .send(function (err, data) {
  319. _this.uploadLoading1 = false;
  320. if (err) {
  321. var a = _this.$refs.upload1.uploadFiles;
  322. a.splice(a.length - 1, a.length);
  323. _this.$message.error("上传失败");
  324. } else {
  325. //上传成功处理
  326. _this.fileList1.push({
  327. name: file.name,
  328. url: data.Location,
  329. uid: file.uid,
  330. });
  331. console.log(data.Location);
  332. }
  333. });
  334. }
  335. },
  336. change(val) {
  337. console.log(val);
  338. },
  339. //添加文章
  340. addContent() {
  341. if (this.contentTitle === "") {
  342. this.$message.error("请输入文章标题");
  343. return;
  344. } else if (this.detail === "") {
  345. this.$message.error("请输入文章内容");
  346. return;
  347. }
  348. console.log(this.detail);
  349. if (this.time()) {
  350. let params = [
  351. {
  352. p: this.fileList1.length ? this.fileList1[0].url : "",
  353. t: this.contentTitle,
  354. c: this.detail.replace(/%/g, "%25"),
  355. },
  356. ];
  357. this.ajax
  358. .post(this.$store.state.api + "addFind", params)
  359. .then((res) => {
  360. this.$message({
  361. message: "添加成功",
  362. type: "success",
  363. });
  364. this.init();
  365. this.getFind();
  366. this.dialogVisible1 = false;
  367. })
  368. .catch((err) => {
  369. this.$message.error("添加失败");
  370. console.error(err);
  371. });
  372. }
  373. },
  374. handleClose(done) {
  375. done();
  376. },
  377. handleCurrentChange(val) {
  378. // console.log(`当前页: ${val}`);
  379. this.page = val;
  380. this.getFind();
  381. },
  382. //查询文章
  383. getFind() {
  384. this.isLoading = true;
  385. let params = { pid: this.pid, page: this.page };
  386. this.ajax
  387. .get(this.$store.state.api + "getFindAdmin", params)
  388. .then((res) => {
  389. this.isLoading = false;
  390. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  391. this.tableData = res.data[0];
  392. })
  393. .catch((err) => {
  394. this.isLoading = false;
  395. console.error(err);
  396. });
  397. },
  398. changeType() {
  399. this.page = 1;
  400. this.getFind();
  401. },
  402. //查看文章详情
  403. getDetail(id) {
  404. let params = { id: id };
  405. this.ajax
  406. .get(this.$store.state.api + "getFindByid", params)
  407. .then((res) => {
  408. this.dialogVisible2 = true;
  409. this.homeDeatail = res.data[0][0];
  410. })
  411. .catch((err) => {
  412. console.error(err);
  413. });
  414. },
  415. //删除文章
  416. deleteFind(id) {
  417. let params = [{ id: id }];
  418. this.$confirm("确定删除此发现文章吗?", "提示", {
  419. confirmButtonText: "确定",
  420. cancelButtonText: "取消",
  421. type: "warning",
  422. })
  423. .then(() => {
  424. this.ajax
  425. .post(this.$store.state.api + "deleteFind", params)
  426. .then((res) => {
  427. this.$message({
  428. message: "删除成功",
  429. type: "success",
  430. });
  431. if (this.page != 1 && this.tableData.length == 1) {
  432. this.page--;
  433. }
  434. this.getFind();
  435. })
  436. .catch((err) => {
  437. this.$message.error("删除失败");
  438. console.error(err);
  439. });
  440. })
  441. .catch(() => {});
  442. },
  443. changeHeight() {
  444. this.tableHeight =
  445. window.innerHeight - this.$refs.table.$el.offsetTop - 200;
  446. if (this.tableHeight <= 530) {
  447. this.tableHeight = 530;
  448. }
  449. // 监听窗口大小变化
  450. let self = this;
  451. window.onresize = function () {
  452. self.tableHeight =
  453. window.innerHeight - self.$refs.table.$el.offsetTop - 200;
  454. if (self.tableHeight <= 530) {
  455. self.tableHeight = 530;
  456. }
  457. };
  458. // this.$refs.table.$el.offsetTop:表格距离浏览器的高度 //200表示你想要调整的表格距离底部的高度(你可以自己随意调整),因为我们一般都有放分页组件的,所以需要给它留一个高度
  459. },
  460. //修改
  461. updatePop(id, index) {
  462. this.init();
  463. this.dialogVisible3 = true;
  464. this.updateJson = this.tableData[index];
  465. this.fileList1 = [];
  466. if (this.tableData[index].poster != "") {
  467. this.fileList1.push({
  468. name: this.tableData[index].poster
  469. .split("//")[1]
  470. .split("/")[1]
  471. .split(".")[0],
  472. url: this.tableData[index].poster,
  473. });
  474. }
  475. this.updateId = id;
  476. },
  477. updateDetail() {
  478. if (this.updateJson.title === "") {
  479. this.$message.error("请输入文章标题");
  480. return;
  481. } else if (this.updateJson.content === "") {
  482. this.$message.error("请输入文章内容");
  483. return;
  484. }
  485. if (this.time()) {
  486. let params = [
  487. {
  488. p: this.fileList1.length ? this.fileList1[0].url : "",
  489. t: this.updateJson.title,
  490. c: this.updateJson.content.replace(/%/g, "%25"),
  491. id: this.updateId,
  492. },
  493. ];
  494. this.ajax
  495. .post(this.$store.state.api + "updateFind", params)
  496. .then((res) => {
  497. this.$message({
  498. message: "修改成功",
  499. type: "success",
  500. });
  501. this.init();
  502. this.getFind();
  503. this.dialogVisible3 = false;
  504. })
  505. .catch((err) => {
  506. this.$message.error("修改失败");
  507. console.error(err);
  508. });
  509. }
  510. },
  511. },
  512. mounted() {
  513. this.$nextTick(function () {
  514. this.page = 1;
  515. this.getFind();
  516. this.changeHeight();
  517. });
  518. },
  519. };
  520. </script>
  521. <style scoped>
  522. .tou {
  523. border-bottom: 1px solid #c9c9c9;
  524. height: 50px;
  525. font-size: 30px;
  526. }
  527. .tian1 {
  528. margin-top: 15px;
  529. }
  530. .tian1 span {
  531. display: block;
  532. }
  533. .tutor_type {
  534. display: flex;
  535. align-items: center;
  536. margin: 15px 0px;
  537. }
  538. .head {
  539. font-size: 20px;
  540. border-bottom: 1px solid;
  541. /* height: 35px; */
  542. display: flex;
  543. align-items: center;
  544. padding-bottom: 10px;
  545. justify-content: space-between;
  546. }
  547. .name {
  548. float: right;
  549. /* margin-top: -30px; */
  550. font-size: 14px;
  551. width: 200px;
  552. }
  553. .cont {
  554. /* font-size: 16px; */
  555. line-height: 34px;
  556. text-indent: 2em;
  557. }
  558. .dialog_diy >>> .el-dialog__header {
  559. background: #3d67bc !important;
  560. padding: 15px 20px;
  561. }
  562. .dialog_diy >>> .el-dialog__title {
  563. color: #fff;
  564. }
  565. .dialog_diy >>> .el-dialog__headerbtn {
  566. top: 19px;
  567. }
  568. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  569. color: #fff;
  570. }
  571. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  572. color: #fff;
  573. }
  574. .student_page {
  575. margin-top: 15px;
  576. }
  577. .dialog_diyA >>> .el-dialog {
  578. min-width: 800px;
  579. }
  580. .dialog_diyH >>> .el-dialog__body {
  581. height: 750px;
  582. overflow: auto;
  583. }
  584. .bbox {
  585. display: flex;
  586. justify-content: flex-end;
  587. margin-top: 15px;
  588. align-items: center;
  589. }
  590. /* table 样式 */
  591. .cont >>> table {
  592. border-top: 1px solid #ccc;
  593. border-left: 1px solid #ccc;
  594. }
  595. .cont >>> table td,
  596. .cont >>> table th {
  597. border-bottom: 1px solid #ccc;
  598. border-right: 1px solid #ccc;
  599. padding: 3px 5px;
  600. }
  601. .cont >>> table th {
  602. border-bottom: 2px solid #ccc;
  603. text-align: center;
  604. }
  605. /* blockquote 样式 */
  606. .cont >>> blockquote {
  607. display: block;
  608. border-left: 8px solid #d0e5f2;
  609. padding: 5px 10px;
  610. margin: 10px 0;
  611. line-height: 1.4;
  612. font-size: 100%;
  613. background-color: #f1f1f1;
  614. }
  615. /* code 样式 */
  616. .cont >>> code {
  617. display: inline-block;
  618. *display: inline;
  619. *zoom: 1;
  620. background-color: #f1f1f1;
  621. border-radius: 3px;
  622. padding: 3px 5px;
  623. margin: 0 3px;
  624. }
  625. .cont >>> pre code {
  626. display: block;
  627. }
  628. /* ul ol 样式 */
  629. .cont >>> ul,
  630. ol {
  631. margin: 10px 0 10px 20px;
  632. }
  633. </style>