Article.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <style lang="scss" scoped>
  2. .preview {
  3. .el-form-item {
  4. margin-bottom: 15px;
  5. }
  6. label,
  7. p {
  8. line-height: 25px !important;
  9. }
  10. }
  11. .el-cascader {
  12. width: 100%;
  13. }
  14. a {
  15. text-decoration: none;
  16. color: #409eff;
  17. cursor: pointer;
  18. }
  19. // 右边
  20. .item-main {
  21. // margin:34px;
  22. // height:600px;
  23. // background: #FFFFFF;
  24. border: 1px solid #dddddd;
  25. box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.13);
  26. border-radius: 20px;
  27. .el-form.over_y {
  28. max-height: calc(100vh - 340px);
  29. }
  30. /deep/.el-form-item__label {
  31. float: none;
  32. }
  33. }
  34. // label样式
  35. .edit_label {
  36. /deep/.el-input__inner {
  37. background: #f5faff;
  38. border: 0px;
  39. padding: 0px;
  40. }
  41. }
  42. /deep/.opicon {
  43. font-weight: bold;
  44. padding: 5px;
  45. color: #3895fe;
  46. }
  47. .tpl_title {
  48. font-size: 18px;
  49. margin: 20px 0;
  50. }
  51. .tpl_form {
  52. margin: 20px;
  53. border: 1px solid #ccc;
  54. border-radius: 20px;
  55. /deep/.el-form-item {
  56. background: none;
  57. }
  58. /deep/.el-form-item__content {
  59. width: 100%;
  60. }
  61. }
  62. .survey_logo {
  63. position: relative;
  64. top: 15px;
  65. left: 20px;
  66. }
  67. .result_dialog .el-dialog {
  68. width: 40%;
  69. margin-top: 20vh !important;
  70. }
  71. .result-item {
  72. height: 35px;
  73. .label {
  74. font-weight: 600;
  75. }
  76. }
  77. .syncitem {
  78. display: flex;
  79. justify-content: space-between;
  80. border-bottom: 1px solid #f4f4f4;
  81. background: #ffffff;
  82. }
  83. .syncitem img {
  84. margin: 10px;
  85. }
  86. .syncbtn {
  87. margin-top: 20px;
  88. text-align: center;
  89. }
  90. /deep/.el-dialog__body {
  91. padding: 10px 12px!important;
  92. background: #ececec;
  93. p {
  94. height: 45px;
  95. overflow: hidden!important;
  96. display: -webkit-box;
  97. -webkit-line-clamp: 2;
  98. -webkit-box-orient: vertical;
  99. padding:10px 10px;
  100. }
  101. }
  102. </style>
  103. <template>
  104. <section>
  105. <p><span>精品导读></span>文章管理</p>
  106. <div class="content">
  107. <div class="filter">
  108. <el-form
  109. size="small"
  110. label-width="70px"
  111. :inline="true"
  112. label-position="left"
  113. >
  114. <el-form-item label="">
  115. <el-input
  116. clearable
  117. placeholder="请输入标题"
  118. v-model="form.name"
  119. ></el-input>
  120. </el-form-item>
  121. <el-form-item>
  122. <el-button type="primary" @click="search">搜索</el-button>
  123. </el-form-item>
  124. <el-form-item label="文章来源">
  125. <el-select
  126. v-model="form.journal_id"
  127. placeholder="请选择期刊"
  128. filterable
  129. clearable
  130. @change="getData()"
  131. @clear="getData()"
  132. >
  133. <el-option
  134. v-for="item in journalSearch"
  135. :key="item.id"
  136. :label="item.name"
  137. :value="item.id"
  138. >
  139. </el-option>
  140. </el-select>
  141. </el-form-item>
  142. <el-form-item style="float: right">
  143. <el-button @click="syncToMP" type="primary">同步到公众号</el-button>
  144. <el-button @click="addArticle" type="primary">发布文章</el-button>
  145. </el-form-item>
  146. <!-- <el-form-item style="float: right" v-if="form.journal_id">
  147. <el-button @click="$router.go(-1)" type="info">返回</el-button>
  148. </el-form-item> -->
  149. </el-form>
  150. </div>
  151. <el-table
  152. class="table"
  153. :data="list"
  154. height="57vh"
  155. border
  156. v-loading="loading"
  157. default-expand-all
  158. row-key="id"
  159. style="width: 100%"
  160. @selection-change="handleSelectionChange"
  161. >
  162. <el-table-column type="selection" width="55"> </el-table-column>
  163. <el-table-column prop="name" label="文章名称" width="380px"> </el-table-column>
  164. <el-table-column prop="img" label="封面图">
  165. <template slot-scope="scope">
  166. <img :src="scope.row.img" alt="" width="120" height="80" />
  167. </template>
  168. </el-table-column>
  169. <el-table-column prop="author" label="作者"></el-table-column>
  170. <el-table-column prop="journal_name" label="来源"></el-table-column>
  171. <el-table-column prop="publish_time" label="出版时间"></el-table-column>
  172. <el-table-column prop="ctime" label="发布时间"></el-table-column>
  173. <el-table-column prop="read_num" label="阅读量" width="80"></el-table-column>
  174. <el-table-column prop="zip" width="150" label="操作">
  175. <template slot-scope="scope">
  176. <el-button class="edit" type="text" @click="edit(scope.row)"
  177. >编辑</el-button
  178. >
  179. <el-button class="del" @click="del(scope.row.id)" type="text"
  180. >删除</el-button
  181. >
  182. </template>
  183. </el-table-column>
  184. </el-table>
  185. <Page
  186. ref="pageButton"
  187. :current="form.page"
  188. :page_size="form.page_size"
  189. :total="total"
  190. @pageChange="gopage"
  191. />
  192. <!-- 同步到微信公众号 -->
  193. <el-dialog
  194. class="fu-dialog"
  195. title="同步到微信公众号"
  196. width="414px"
  197. :close-on-click-modal="false"
  198. :visible.sync="dialogVisible"
  199. >
  200. <!-- <div>
  201. <img :src="journalLogo" alt="">
  202. </div> -->
  203. <div v-loading="loading1">
  204. <div v-if="multipleSelection.length" style="position: relative">
  205. <img
  206. :src="multipleSelection[0].img"
  207. alt=""
  208. width="390px"
  209. height="170px"
  210. />
  211. <p
  212. style="
  213. position: absolute;
  214. bottom: 20px;
  215. left: 10px;
  216. font-weight: bold;
  217. color: #ffffff;
  218. right: 10px;
  219. "
  220. >
  221. {{ multipleSelection[0].name }}
  222. </p>
  223. </div>
  224. <div v-if="multipleSelection.length">
  225. <div
  226. class="syncitem"
  227. v-for="(item, index) in multipleSelection.slice(1, 8)"
  228. :key="index"
  229. >
  230. <p>{{ item.name.substring(0,43) }}</p>
  231. <img :src="item.img" alt="" width="48px" height="48px" />
  232. </div>
  233. </div>
  234. </div>
  235. <div class="syncbtn">
  236. <el-button type="normal" size="small" @click="dialogVisible = false"
  237. >取消</el-button
  238. >
  239. <el-button type="primary" size="small" @click="saveSyncToMP()"
  240. >确定</el-button
  241. >
  242. </div>
  243. </el-dialog>
  244. </div>
  245. </section>
  246. </template>
  247. <script>
  248. import Page from "../../components/Page";
  249. import fuEditor from "../../components/fuEditor";
  250. export default {
  251. components: {
  252. Page,
  253. fuEditor,
  254. },
  255. data() {
  256. return {
  257. loading: false,
  258. loading1: false,
  259. form: { name: "", page: 1, page_size: 20 },
  260. total: 1,
  261. list: [{ name: "2333" }],
  262. loading: false,
  263. rules: {
  264. name: [{ required: true, message: "请输入标题", trigger: "blur" }],
  265. },
  266. dialogVisible: false,
  267. journalLogo: "",
  268. multipleSelection: [],
  269. journalSearch: [],
  270. };
  271. },
  272. methods: {
  273. syncToMP() {
  274. if (!this.multipleSelection) {
  275. this.$message.error("请勾选需要同步到公众号的文章!");
  276. return;
  277. }
  278. this.dialogVisible = true;
  279. },
  280. saveSyncToMP() {
  281. let ids = "";
  282. this.multipleSelection.forEach((item, index) => {
  283. if (index == 0) {
  284. ids += item.id.toString();
  285. } else {
  286. ids += "," + item.id.toString();
  287. }
  288. });
  289. this.loading1 = true;
  290. this.$api.syncToMP({ ids: ids }).then((res) => {
  291. this.loading1 = false;
  292. if (res.data.code == 0) {
  293. this.$confirm(
  294. "同步成功,已发送到微信公众号图文消息,即可可前往微信公众号预览!",
  295. "提示",
  296. {
  297. confirmButtonText: "确定",
  298. showCancelButton: false,
  299. type: "success",
  300. }
  301. ).then(() => {
  302. this.dialogVisible = false;
  303. });
  304. } else {
  305. this.$confirm("同步失败!" + res.data.message, "提示", {
  306. confirmButtonText: "确定",
  307. showCancelButton: false,
  308. type: "error",
  309. });
  310. }
  311. });
  312. },
  313. handleSelectionChange(val) {
  314. console.log(val);
  315. this.multipleSelection = val;
  316. },
  317. search() {
  318. let parm = this.form;
  319. this.getData();
  320. },
  321. openDiag() {
  322. this.form1 = {};
  323. this.dialogVisible = true;
  324. this.dialogTitle = "发送消息";
  325. },
  326. addArticle() {
  327. this.$router.push({ path: "/article/article/add" });
  328. },
  329. gopage(size) {
  330. if (size) {
  331. this.form.page_size = size;
  332. }
  333. this.form.page = this.$refs.pageButton.page;
  334. this.getData();
  335. },
  336. getData() {
  337. var parm = this.form;
  338. this.loading = true;
  339. this.$api.searchJournalList().then((res) => {
  340. this.journalSearch = res.data.data;
  341. });
  342. this.$api.getArticleList(parm).then((res) => {
  343. console.log(res);
  344. this.list = res.data.data.list;
  345. this.total = res.data.data.total;
  346. this.loading = false;
  347. });
  348. },
  349. del(id) {
  350. this.$confirm("确定删除吗", "提示", {
  351. type: "warning",
  352. }).then(() => {
  353. this.$api.delArticle({ id: id }).then((res) => {
  354. this.$message({
  355. message: "删除成功",
  356. type: "success",
  357. });
  358. this.getData();
  359. });
  360. });
  361. },
  362. edit(row) {
  363. this.$router.push({
  364. path: "/article/article/add",
  365. query: { id: row.id },
  366. });
  367. },
  368. save() {
  369. this.$refs["form1"].validate((valid) => {
  370. if (valid) {
  371. let parm = this.form1;
  372. let id = this.form1.id;
  373. parm.receiver_id = JSON.stringify(parm.receiver_id);
  374. if (id) {
  375. this.$api.editMessage(parm).then((res) => {
  376. if (res.data.code == 0) {
  377. this.$message({
  378. type: "success",
  379. message: "保存成功!",
  380. });
  381. } else {
  382. this.$message.error("保存失败!");
  383. }
  384. this.getData();
  385. this.dialogVisible = false;
  386. });
  387. } else {
  388. this.$api.addMessage(parm).then((res) => {
  389. if (res.data.code == 0) {
  390. this.$message({
  391. type: "success",
  392. message: "保存成功!",
  393. });
  394. } else {
  395. this.$message.error("保存失败!");
  396. }
  397. this.getData();
  398. this.dialogVisible = false;
  399. });
  400. }
  401. }
  402. });
  403. },
  404. },
  405. created() {
  406. if (this.$route.query.id) {
  407. this.form.journal_id = this.$route.query.id;
  408. }
  409. this.getData();
  410. },
  411. beforeRouteEnter(to, from, next) {
  412. next((vm) => {
  413. if (from.path.indexOf("add") >= 0) {
  414. vm.getData();
  415. }
  416. });
  417. },
  418. };
  419. </script>