tacticsTimeLine.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <script setup>
  2. import { raiInterface } from "@/api/api.js";
  3. import mPage from "@/components/mPage.vue";
  4. import { onMounted, reactive, ref, toRefs } from "vue";
  5. import { ElMessageBox, ElMessage } from "element-plus";
  6. const pageState = reactive({
  7. page_no: 1,
  8. total: 0, //条数
  9. PageSize: 10, //每页显示几条
  10. visibleRange: 3, //可见范围
  11. dataTableList: [],
  12. statusValue: "",
  13. statusOptions: [
  14. {
  15. label: "显示",
  16. value: 1,
  17. },
  18. {
  19. label: "隐藏",
  20. value: 0,
  21. },
  22. ],
  23. addOfEditDialog: false, //添加或者编辑
  24. addOfEditText: "",
  25. dataForm: {
  26. Link: "", // 链接
  27. PublishTime: "", //日期
  28. Content: "", //文本内容
  29. TimeLineId: 0,
  30. },
  31. dataRules: {
  32. PublishTime: [{ required: true, message: "请选择日期", trigger: "change" }],
  33. Content: [{ required: true, message: "请输入文本内容", trigger: "blur" }],
  34. },
  35. froalaConfig: {
  36. toolbarButtons: ["bold", "italic", "underline", "strikeThrough", "insertHR", "fontSize", "align", "undo", "redo"],
  37. height: 200,
  38. fontSizeDefaultSelection: "16",
  39. quickInsertEnabled: false,
  40. theme: "dark", //主题
  41. placeholderText: "请输入文本内容",
  42. language: "zh_cn",
  43. events: {
  44. initialized: function () {
  45. this.toolbar.hide();
  46. },
  47. },
  48. },
  49. });
  50. // 获取数据
  51. async function getDataList() {
  52. const res = await raiInterface.getTacticsTimeLineList({
  53. PageSize: pageState.PageSize,
  54. CurrentIndex: pageState.page_no,
  55. Status: pageState.statusValue === 0 || pageState.statusValue === 1 ? pageState.statusValue : 2,
  56. });
  57. if (res.Ret === 200) {
  58. pageState.total = res.Data.Paging.Totals || 0;
  59. pageState.dataTableList = res.Data.List;
  60. pageState.visibleRange = res.Data.Status;
  61. }
  62. }
  63. // 添加
  64. function addReport() {
  65. pageState.addOfEditDialog = true;
  66. pageState.addOfEditText = "添加";
  67. }
  68. // 编辑
  69. function editReport(item) {
  70. pageState.dataForm = {
  71. Link: item.Link, // 链接
  72. PublishTime: item.PublishTime.replace(/\./g, "-"), //日期
  73. Content: item.Content, //文本内容
  74. TimeLineId: item.TimeLineId,
  75. };
  76. pageState.addOfEditText = "编辑";
  77. pageState.addOfEditDialog = true;
  78. }
  79. let ruleForm = ref(null);
  80. // 关闭弹框
  81. function handleClose() {
  82. ruleForm.value.resetFields();
  83. pageState.addOfEditDialog = false;
  84. pageState.dataForm = {
  85. Link: "", // 链接
  86. PublishTime: "", //日期
  87. Content: "", //文本内容
  88. TimeLineId: 0,
  89. };
  90. }
  91. // 弹框的保存事件
  92. function confirmPerson() {
  93. ruleForm.value.validate(async (valid) => {
  94. if (valid) {
  95. pageState.dataForm.Content = pageState.dataForm.Content.replace(/<p data-f-id=\"pbf\".*?<\/p>/g, "");
  96. const res = await raiInterface.tacticsTimeLinePreserveAndPublish({
  97. ...pageState.dataForm,
  98. });
  99. if (res.Ret === 200) {
  100. ElMessage.success("操作成功");
  101. handleClose();
  102. getDataList();
  103. }
  104. }
  105. });
  106. }
  107. // 导出pv uv
  108. function exportPvUv(item) {
  109. const url = import.meta.env.VITE_APP_API_ROOT + "/cygx/tacticsTimeLine/PvExport?TimeLineId=" + item.TimeLineId + "&" + localStorage.getItem("auth") || "";
  110. return url;
  111. }
  112. // 删除
  113. function deleteBtn(item) {
  114. ElMessageBox.confirm(`确定删除这条内容吗?`, "提示", {
  115. confirmButtonText: "确定",
  116. cancelButtonText: "取消",
  117. type: "warning",
  118. })
  119. .then(async () => {
  120. const res = await raiInterface.tacticsTimeLineDelete({ TimeLineId: item.TimeLineId });
  121. if (res.Ret === 200) {
  122. ElMessage.success("删除成功!");
  123. let page_num = Math.ceil((pageState.total - 1) / pageState.PageSize);
  124. if (pageState.page_no > page_num) {
  125. pageState.page_no = page_num;
  126. }
  127. getDataList();
  128. }
  129. })
  130. .catch(() => {
  131. ElMessage({
  132. type: "info",
  133. message: `已取消删除`,
  134. });
  135. });
  136. }
  137. // 分页
  138. function handleCurrentChange(page) {
  139. pageState.page_no = page;
  140. getDataList();
  141. }
  142. // 选择的change 事件
  143. function listChangeHandel() {
  144. pageState.page_no = 1;
  145. getDataList();
  146. }
  147. // 一键发布/取消发布报告接口
  148. async function tacticsTimeLineAllCancel() {
  149. const res = await raiInterface.tacticsTimeLineAllCancel();
  150. if (res.Ret === 200) {
  151. ElMessage.success("操作成功");
  152. }
  153. getDataList();
  154. }
  155. // 发布/取消发布报告 显示隐藏
  156. async function tacticsTimeLineCancel(item) {
  157. const res = await raiInterface.tacticsTimeLineCancel({
  158. TimeLineId: item.TimeLineId,
  159. });
  160. if (res.Ret === 200) {
  161. ElMessage.success("操作成功");
  162. }
  163. getDataList();
  164. }
  165. onMounted(() => {
  166. getDataList();
  167. });
  168. const { page_no, total, PageSize, visibleRange, dataTableList, statusValue, statusOptions, addOfEditDialog, addOfEditText, dataForm, dataRules, froalaConfig } = toRefs(pageState);
  169. </script>
  170. <template>
  171. <div class="container tactics-time-line">
  172. <!-- 头部 -->
  173. <el-card style="margin-bottom: 20px">
  174. <div style="display: flex; justify-content: space-between; align-items: center">
  175. <el-radio-group v-model="visibleRange" @input="tacticsTimeLineAllCancel">
  176. <el-radio :label="0">内部可见</el-radio>
  177. <el-radio :label="1">全部可见</el-radio>
  178. </el-radio-group>
  179. <el-button @click="addReport" type="primary">添加</el-button>
  180. </div>
  181. </el-card>
  182. <!-- 表格部分 -->
  183. <el-card>
  184. <el-select v-model="statusValue" placeholder="请选择状态" @change="listChangeHandel" clearable style="margin-bottom: 20px">
  185. <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
  186. </el-select>
  187. <el-table :data="dataTableList" border align="center">
  188. <el-table-column prop="PublishTime" label="日期" width="130" align="center"> </el-table-column>
  189. <el-table-column min-width="350">
  190. <template #header>
  191. <div style="text-align: center">文本</div>
  192. </template>
  193. <template #default="{ row }">
  194. <span v-html="row.Content"></span>
  195. </template>
  196. </el-table-column>
  197. <el-table-column prop="Title" label="报告/图表标题" min-width="250" align="center"> </el-table-column>
  198. <el-table-column label="pv/uv" width="100" align="center">
  199. <template #default="{ row }">
  200. <div class="pv-uv-download">
  201. <span>{{ row.Pv }}/{{ row.Uv }}</span>
  202. <a :href="exportPvUv(row)" download>
  203. <img src="~@/assets/img/rai_m/pvuv_download.png" alt="" />
  204. </a>
  205. </div>
  206. </template>
  207. </el-table-column>
  208. <el-table-column label="状态" width="180" align="center">
  209. <template #default="{ row }">
  210. <el-radio-group v-model="row.Status" @input="tacticsTimeLineCancel(row)">
  211. <el-radio :label="0">隐藏</el-radio>
  212. <el-radio :label="1">显示</el-radio>
  213. </el-radio-group>
  214. </template>
  215. </el-table-column>
  216. <el-table-column prop="ModifyTime" label="更新时间" width="180" align="center"> </el-table-column>
  217. <el-table-column label="操作" width="100" align="center">
  218. <template #default="{ row }">
  219. <span class="editsty" @click="editReport(row)">编辑&nbsp;&nbsp;</span>
  220. <span v-if="row.Status === 0" class="deletesty" @click="deleteBtn(row)">删除</span>
  221. </template>
  222. </el-table-column>
  223. </el-table>
  224. <el-col :span="24" class="toolbar">
  225. <m-page :total="total" :page_no="page_no" :pageSize="10" @handleCurrentChange="handleCurrentChange" />
  226. </el-col>
  227. </el-card>
  228. <!-- 弹框部分 -->
  229. <el-dialog v-model="addOfEditDialog" :title="addOfEditText" draggable :close-on-click-modal="false" :modal-append-to-body="false" center width="661px" @close="handleClose">
  230. <el-form :model="dataForm" :rules="dataRules" ref="ruleForm">
  231. <el-form-item prop="PublishTime">
  232. <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="请选择日期" v-model="dataForm.PublishTime" style="width: 100%"></el-date-picker>
  233. </el-form-item>
  234. <el-form-item prop="Content">
  235. <div class="fr-wrapper" style="width: 100%">
  236. <froala id="froala-editor" ref="froalaEditor" :tag="'textarea'" :config="froalaConfig" v-model="dataForm.Content"></froala>
  237. </div>
  238. </el-form-item>
  239. <el-form-item>
  240. <el-input type="textarea" placeholder="请输入报告或图表链接(网页版详情链接)" v-model="dataForm.Link"></el-input>
  241. </el-form-item>
  242. </el-form>
  243. <template #footer>
  244. <span class="dialog-footer">
  245. <el-button type="primary" @click="confirmPerson">确定</el-button>
  246. <el-button @click="handleClose">取消</el-button>
  247. </span>
  248. </template>
  249. </el-dialog>
  250. </div>
  251. </template>
  252. <style scoped lang="scss">
  253. .tactics-time-line {
  254. .pv-uv-download {
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. img {
  259. width: 14px;
  260. height: 14px;
  261. margin-left: 10px;
  262. }
  263. }
  264. }
  265. .fr-wrapper {
  266. border-top: 1px solid #cccccc !important;
  267. border-bottom: 1px solid #cccccc !important;
  268. }
  269. </style>