publish.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <keep-alive>
  3. <div class="app-container">
  4. <span><i class="el-icon-user"></i> 个人发表 - {{nickName}}</span>
  5. <el-divider></el-divider>
  6. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  7. <el-form-item label="内容" prop="contents">
  8. <el-input
  9. v-model="queryParams.contents"
  10. placeholder="请输入内容"
  11. clearable
  12. size="small"
  13. @keyup.enter.native="handleQuery"
  14. />
  15. </el-form-item>
  16. <el-form-item label="发表时间">
  17. <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  21. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-row :gutter="10" class="mb8">
  25. <el-col :span="1.5">
  26. <el-button
  27. type="danger"
  28. icon="el-icon-delete"
  29. size="mini"
  30. :disabled="multiple"
  31. @click="handleDelete"
  32. v-hasPermi="['system:publish:remove']"
  33. >删除</el-button>
  34. </el-col>
  35. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  36. </el-row>
  37. <el-table v-loading="loading" :data="publishList" @selection-change="handleSelectionChange">
  38. <el-table-column type="selection" width="55" align="center" />
  39. <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
  40. <el-table-column label="发表内容" align="center" prop="contents" :formatter="contentsFormat" width="450"/>
  41. <el-table-column label="发布时间" align="center" prop="createTime" width="160"/>
  42. <el-table-column
  43. label="纪念留言"
  44. align="center"
  45. prop="message"
  46. :formatter="messageFormat"
  47. width="100"
  48. />
  49. <el-table-column label="点赞数" align="center" prop="thumbs" />
  50. <el-table-column label="评论数" align="center" prop="comments" />
  51. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  52. <template slot-scope="scope">
  53. <el-button
  54. size="mini"
  55. type="text"
  56. icon="el-icon-search"
  57. @click="handleUpdate(scope.row)"
  58. v-hasPermi="['system:publish:edit']"
  59. >查看</el-button>
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-delete"
  64. @click="handleDelete(scope.row)"
  65. v-hasPermi="['system:publish:remove']"
  66. >删除</el-button>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <pagination
  71. v-show="total>0"
  72. :total="total"
  73. :page.sync="queryParams.pageNum"
  74. :limit.sync="queryParams.pageSize"
  75. @pagination="getList"
  76. />
  77. <!-- 添加或修改我的近况(发)对话框 -->
  78. <el-dialog :visible.sync="open" width="600px" append-to-body :close-on-click-modal=false>
  79. <el-card>
  80. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  81. <el-card shadow="hover">
  82. <div style="line-height:150%">{{form.contents}}</div>
  83. <el-divider />
  84. <div>
  85. <div style="float: left;padding:0px 0px 10px;">
  86. <el-tag type="info"> 点赞数:{{form.thumbs}} </el-tag>
  87. </div>
  88. <div v-if="form.message == 'Y'" style="float: right;font-size: 10px;color:#909399;">
  89. <div style="padding:1px;">留 念 人:{{form.messageUser}}</div>
  90. <div style="padding:2px;">发布时间:{{form.createTime}}</div>
  91. </div>
  92. </div>
  93. </el-card>
  94. <div class="block1">
  95. <el-collapse>
  96. <el-collapse-item>
  97. <template slot="title">
  98. <i class="header-icon el-icon-picture-outline-round"></i> 查看图片
  99. </template>
  100. <div v-for="item in imgList" :key="item.key" class="block">
  101. <el-image :key="item.key" :src="item.value" :preview-src-list="[item.value]" :fit="'cover'" class="images" />
  102. </div>
  103. </el-collapse-item>
  104. </el-collapse>
  105. </div>
  106. </el-form>
  107. <el-card shadow="hover" :body-style="{height:'200px'}">
  108. <div slot="header" class="clearfix">
  109. <span>评论</span>
  110. <div style="float: right; padding: 3px 0">{{form.comments}}</div>
  111. </div>
  112. <el-carousel :autoplay="false" :loop="false" arrow="always">
  113. <el-carousel-item v-for="item in commentList" :key="item.id">
  114. <el-row :gutter="10" type="flex" justify="start">
  115. <el-col :span="3" style="padding: 10px;margin:0 auto;text-align:center;">
  116. <el-avatar :size="40" :src="baseUrl+item.appUserUrl"></el-avatar>
  117. <div style="width: 100%;margin:0 auto;text-align:center;">
  118. <span>{{item.appUser}}</span>
  119. </div>
  120. </el-col>
  121. <el-col :span="21" style="padding: 10px">
  122. <div style="float: right;">
  123. <el-button type="danger" size="mini" icon="el-icon-delete" circle @click="delComm(item)"/>
  124. </div>
  125. <div style="float: top;font-size:11px;color:#909399;padding:0px 0px 10px">
  126. {{item.createTime}}
  127. </div>
  128. <div style="float: bottom;font-size:12px;height:120px">
  129. {{item.contents}}
  130. </div>
  131. </el-col>
  132. </el-row>
  133. </el-carousel-item>
  134. </el-carousel>
  135. </el-card>
  136. </el-card>
  137. <div slot="footer" class="dialog-footer">
  138. <el-button @click="cancel" type="primary">关 闭</el-button>
  139. </div>
  140. </el-dialog>
  141. </div>
  142. </keep-alive>
  143. </template>
  144. <script>
  145. import { listPublish, getPublish, delPublish, addPublish, updatePublish, exportPublish,listComment,delComment } from "@/api/system/publish";
  146. import { getUser } from "@/api/system/appUser";
  147. export default {
  148. name: "Publish",
  149. data() {
  150. return {
  151. baseUrl: '',
  152. // 遮罩层
  153. loading: true,
  154. // 选中数组
  155. ids: [],
  156. pid: null,
  157. // 非单个禁用
  158. single: true,
  159. // 非多个禁用
  160. multiple: true,
  161. // 显示搜索条件
  162. showSearch: true,
  163. // 日期范围
  164. dateRange: [],
  165. // 总条数
  166. total: 0,
  167. // 我的近况表格数据
  168. publishList: [],
  169. imgList:[],
  170. messageOptions: [],
  171. // 弹出层标题
  172. title: "",
  173. // 是否显示弹出层
  174. open: false,
  175. nickName: "",
  176. commentList: [],
  177. // 查询参数
  178. queryParams: {
  179. pageNum: 1,
  180. pageSize: 10,
  181. appUserId: null,
  182. contents: null,
  183. message: null,
  184. messageUserId: null,
  185. deleted: null,
  186. },
  187. // 表单参数
  188. form: {},
  189. // 表单校验
  190. rules: {
  191. }
  192. };
  193. },
  194. activated() {
  195. this.init();
  196. },
  197. created(){
  198. this.init();
  199. },
  200. methods: {
  201. init(){
  202. this.baseUrl = process.env.VUE_APP_BASE_API;
  203. const uid = this.$route.query.uid;
  204. this.queryParams.appUserId = uid;
  205. this.getDicts("sys_yes_no").then(response => {
  206. this.messageOptions = response.data;
  207. });
  208. this.getUser(uid);
  209. this.getList();
  210. },
  211. getUser(id){
  212. getUser(id).then(response => {
  213. const nickName = response.data.nickName;
  214. this.nickName = nickName == null ? "全部" : nickName;
  215. });
  216. },
  217. /** 查询我的近况(发)列表 */
  218. getList() {
  219. this.loading = true;
  220. this.queryParams.deleted = 'N'
  221. listPublish(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  222. this.publishList = response.rows;
  223. this.total = response.total;
  224. this.loading = false;
  225. });
  226. },
  227. // 是否纪念留言 字典翻译
  228. messageFormat(row, column) {
  229. return this.selectDictLabel(this.messageOptions, row.message);
  230. },
  231. contentsFormat(row, column) {
  232. var len = 28;
  233. if(row.contents.length >= len) {
  234. return row.contents.substr(0,len)+"...";
  235. }
  236. return row.contents;
  237. },
  238. // 取消按钮
  239. cancel() {
  240. this.open = false;
  241. this.reset();
  242. },
  243. // 表单重置
  244. reset() {
  245. this.form = {
  246. id: null,
  247. appUserId: null,
  248. contents: null,
  249. message: null,
  250. messageUserId: null,
  251. thumbs: null,
  252. createBy: null,
  253. createTime: null,
  254. updateBy: null,
  255. updateTime: null,
  256. remark: null,
  257. imgList: []
  258. };
  259. this.resetForm("form");
  260. },
  261. /** 搜索按钮操作 */
  262. handleQuery() {
  263. this.queryParams.pageNum = 1;
  264. this.getList();
  265. },
  266. /** 重置按钮操作 */
  267. resetQuery() {
  268. this.dateRange = [];
  269. this.resetForm("queryForm");
  270. this.handleQuery();
  271. },
  272. // 多选框选中数据
  273. handleSelectionChange(selection) {
  274. this.ids = selection.map(item => item.id)
  275. this.single = selection.length!==1
  276. this.multiple = !selection.length
  277. },
  278. /** 新增按钮操作 */
  279. handleAdd() {
  280. this.reset();
  281. this.open = true;
  282. this.title = "添加我的发表";
  283. },
  284. /** 修改按钮操作 */
  285. handleUpdate(row) {
  286. this.reset();
  287. const id = row.id || this.ids;
  288. getPublish(id).then(response => {
  289. this.form = response.data;
  290. this.title = "查看我的发表";
  291. this.imgList = [];
  292. var apiUrl = process.env.VUE_APP_BASE_API;
  293. var items = response.data.imgList;
  294. for (const i in items) {
  295. var url = apiUrl + items[i].url;
  296. this.imgList.push({ key: items[i].id, value: url})
  297. }
  298. this.listComment(id);
  299. });
  300. this.$nextTick(function(){
  301. this.open = true;
  302. });
  303. },
  304. listComment(id) {
  305. listComment(id).then(res => {
  306. this.commentList = res.rows;
  307. });
  308. },
  309. /** 提交按钮 */
  310. submitForm() {
  311. this.$refs["form"].validate(valid => {
  312. if (valid) {
  313. if (this.form.id != null) {
  314. updatePublish(this.form).then(response => {
  315. if (response.code === 200) {
  316. this.msgSuccess("修改成功");
  317. this.open = false;
  318. this.getList();
  319. }
  320. });
  321. } else {
  322. addPublish(this.form).then(response => {
  323. if (response.code === 200) {
  324. this.msgSuccess("新增成功");
  325. this.open = false;
  326. this.getList();
  327. }
  328. });
  329. }
  330. }
  331. });
  332. },
  333. /** 删除按钮操作 */
  334. handleDelete(row) {
  335. const ids = row.id || this.ids;
  336. this.$confirm('是否确认删除?', "警告", {
  337. confirmButtonText: "确定",
  338. cancelButtonText: "取消",
  339. type: "warning"
  340. }).then(function() {
  341. return delPublish(ids);
  342. }).then(() => {
  343. this.getList();
  344. this.msgSuccess("删除成功");
  345. }).catch(function() {});
  346. },
  347. /** 导出按钮操作 */
  348. handleExport() {
  349. const queryParams = this.queryParams;
  350. this.$confirm('是否确认导出所有我的发表数据项?', "警告", {
  351. confirmButtonText: "确定",
  352. cancelButtonText: "取消",
  353. type: "warning"
  354. }).then(function() {
  355. return exportPublish(queryParams);
  356. }).then(response => {
  357. this.download(response.msg);
  358. }).catch(function() {});
  359. },
  360. delComm(item) {
  361. var id = item.id;
  362. this.$confirm('是否删除这条评论?', "警告", {
  363. confirmButtonText: "确定",
  364. cancelButtonText: "取消",
  365. type: "warning"
  366. }).then(function() {
  367. return delComment(id);
  368. }).then(() => {
  369. this.listComment(item.publishId);
  370. this.form.comments -= 1;
  371. this.msgSuccess("删除成功");
  372. }).catch(function() {});
  373. }
  374. }
  375. };
  376. </script>
  377. <style>
  378. .el-dialog__body {
  379. padding: 10px 20px ! important;
  380. }
  381. /* .el-form-item {
  382. margin-bottom: 8px;
  383. } */
  384. .block {
  385. padding: 1px 1px 0px;
  386. display: inline-block;
  387. align-items: center;
  388. }
  389. .block1 {
  390. width: 100%;
  391. padding: 10px 0px 10px;
  392. }
  393. .images {
  394. width: 140px;
  395. height: 140px;
  396. display: block;
  397. }
  398. .image-slot {
  399. display: flex ! important;
  400. justify-content: center ! important;
  401. align-items: center ! important;
  402. width: 100% ! important;
  403. height: 100% ! important;
  404. background: #f5f7fa ! important;
  405. color: #909399 ! important;
  406. }
  407. .el-divider--horizontal {
  408. margin: 10px 0px ! important;
  409. }
  410. .el-card__body {
  411. padding: 12px ! important;
  412. }
  413. .el-carousel__item {
  414. height: 200px ! important;
  415. }
  416. </style>