dataList.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="data-list" v-loading="loading" element-loading-text="加载中...">
  3. <el-table
  4. :data="dataList"
  5. style="width: 100%"
  6. header-row-class-name="headerBg"
  7. empty-text="没有文档信息"
  8. >
  9. <el-table-column prop="id" label="ID" align="center" width="80" />
  10. <el-table-column
  11. prop="title"
  12. label="文档名称"
  13. align="left"
  14. min-width="180"
  15. />
  16. <el-table-column
  17. prop="user_name"
  18. label="创建人"
  19. align="center"
  20. width="150"
  21. />
  22. <el-table-column
  23. prop="type_name"
  24. label="所属分类"
  25. align="center"
  26. width="150"
  27. />
  28. <el-table-column
  29. prop="create_time"
  30. label="创建时间"
  31. align="center"
  32. width="150"
  33. />
  34. <el-table-column
  35. prop="status"
  36. label="文档状态"
  37. align="center"
  38. width="150"
  39. >
  40. <template #default="scope">
  41. <div v-if="scope.row.status == 5">启用</div>
  42. <div v-if="scope.row.status == 6">停用</div>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="操作" align="center" :width="editWidth()">
  46. <template #default="scope">
  47. <div class="btns">
  48. <el-button
  49. type="primary"
  50. size="small"
  51. v-if="allowEdit"
  52. @click="btnEdit(scope.row.id)"
  53. ><svg-icon icon-class="edit" />编辑</el-button
  54. >
  55. <el-button
  56. type="danger"
  57. size="small"
  58. v-if="allowDelete"
  59. @click="btnDelete(scope.row.id)"
  60. ><svg-icon icon-class="delete" />删除</el-button
  61. >
  62. </div>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <div class="page-info">
  67. <el-pagination
  68. :currentPage="queryForm.page"
  69. :page-size="queryForm.pageSize"
  70. :total="recordCount"
  71. :page-count="pageTotal"
  72. background
  73. layout="prev, pager, next"
  74. @current-change="ChangePage"
  75. >
  76. </el-pagination>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import { pageDocument, deleteDocument } from "@/api/document";
  82. export default {
  83. props: {
  84. queryForm: {
  85. type: Object,
  86. default: () => {
  87. return {
  88. page: 1,
  89. pageSize: 10,
  90. title: "",
  91. category_id: "",
  92. status: "",
  93. };
  94. },
  95. },
  96. allowEdit: {
  97. type: Boolean,
  98. default: false,
  99. },
  100. allowDelete: {
  101. type: Boolean,
  102. default: false,
  103. },
  104. },
  105. watch: {
  106. queryForm: {
  107. handler: function (val) {
  108. this.search();
  109. },
  110. // immediate: true,//立即执行
  111. deep: true,
  112. },
  113. },
  114. data() {
  115. return {
  116. loading: false,
  117. dialogVisible: false, //控制产品审核
  118. currentDataId: 0,
  119. recordCount: 0,
  120. pageTotal: 1,
  121. dataList: [],
  122. currentData: {},
  123. };
  124. },
  125. mounted() {
  126. this.search();
  127. },
  128. methods: {
  129. editWidth() {
  130. if (this.allowDelete && this.allowEdit) {
  131. return 200;
  132. }
  133. if (this.allowDelete || this.allowEdit) {
  134. return 120;
  135. }
  136. return 100;
  137. },
  138. onFocusVal(e) {
  139. let _this = this;
  140. _this.currentDataId = e.target.dataset.id;
  141. },
  142. onChangeVal(e) {
  143. let _this = this;
  144. let par = {
  145. id: _this.currentDataId,
  146. val: e,
  147. };
  148. },
  149. btnDelete(e) {
  150. let _this = this;
  151. let par = {
  152. id: e,
  153. };
  154. _this
  155. .$confirm("您是否确认删除该记录?", "提示", {
  156. confirmButtonText: "确认",
  157. cancelButtonText: "取消",
  158. type: "warning",
  159. })
  160. .then((res) => {
  161. // console.log("AAA")
  162. deleteDocument(par).then((res) => {
  163. _this.search();
  164. });
  165. })
  166. .catch(() => {});
  167. },
  168. searchData() {
  169. let _this = this;
  170. _this.dialogVisible = false;
  171. _this.search();
  172. },
  173. //编辑
  174. btnEdit(e) {
  175. let _this = this;
  176. let a = document.createElement("a");
  177. a.href = "#/document/create?articleId=" + e; // 使用 hash
  178. a.target = "_blank";
  179. a.click();
  180. // _this.$router.push({path:"/document/create",query:{articleId:e}})
  181. },
  182. handleClose() {
  183. let _this = this;
  184. _this.currentData = {};
  185. _this.dialogVisible = false;
  186. },
  187. //搜索
  188. search() {
  189. let _this = this;
  190. _this.loading = true; // Set loading to true before API call
  191. pageDocument(_this.queryForm)
  192. .then((res) => {
  193. if (!res) {
  194. _this.loading = false; // Set loading to false if no response
  195. return;
  196. }
  197. _this.dataList = res.data.dataList.filter(
  198. (el) => el.is_template == 0
  199. );
  200. _this.recordCount = res.data.totalRecord;
  201. _this.pageTotal = res.data.pageTotal;
  202. _this.loading = false; // Set loading to false after data is processed
  203. })
  204. .catch(() => {
  205. _this.loading = false; // Set loading to false if there's an error
  206. });
  207. },
  208. //修改分页
  209. ChangePage(e) {
  210. let _this = this;
  211. _this.queryForm.page = e;
  212. _this.search();
  213. },
  214. },
  215. };
  216. </script>
  217. <style lang="scss">
  218. @import "./dataList.scss";
  219. </style>