serviceFile.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="app-container consult-list">
  3. <h3>
  4. 数据集
  5. <el-tooltip
  6. content="数据集是存放服务的数据文件,支持JSON、EXCEL格式文件。用户可下载文件获取数据。"
  7. placement="top-start"
  8. effect="light"
  9. >
  10. <i class="el-icon-question"></i>
  11. </el-tooltip>
  12. </h3>
  13. <el-divider></el-divider>
  14. <el-row type="flex" justify="space-between">
  15. <el-col :span="18">
  16. <el-form :inline="true" :model="table.query.data">
  17. <el-form-item>
  18. <el-input
  19. placeholder="数据集名称"
  20. v-model="table.query.data.title"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button
  25. type="primary"
  26. @click="getOpenDataList"
  27. icon="Search"
  28. size="small"
  29. >
  30. 查询
  31. </el-button>
  32. </el-form-item>
  33. </el-form>
  34. </el-col>
  35. <el-col :span="2" style="text-align: right">
  36. <el-upload
  37. ref="upload"
  38. name="file"
  39. :action="uploadUrl"
  40. :headers="headers"
  41. :before-upload="handleBeforeUpload"
  42. :on-success="handleUploadSuccess"
  43. :on-error="handleUploadError"
  44. :data="uploadData"
  45. :show-file-list="false"
  46. >
  47. <el-button size="small" type="primary">添加数据集</el-button>
  48. </el-upload>
  49. </el-col>
  50. </el-row>
  51. <el-row class="table_box">
  52. <el-table
  53. stripe
  54. :data="table.list"
  55. :height="table.height"
  56. style="width: 100%"
  57. size="small"
  58. :header-cell-style="{
  59. background: '#ebf3fb',
  60. color: '#333',
  61. padding: '4px 0',
  62. 'border-right': '1px solid #fff',
  63. }"
  64. >
  65. <el-table-column type="index" align="center" label="序号" :index="1"/>
  66. <el-table-column
  67. show-overflow-tooltip
  68. v-for="(param, index) in table.params"
  69. :key="index"
  70. header-align="center"
  71. :align="param.align ? param.align : 'center'"
  72. :width="param.width ? param.width : 'auto'"
  73. :prop="param.paramCode"
  74. :label="param.paramName"
  75. >
  76. <template #default="scope">
  77. <span v-if="param.paramCode != 'viewNum'">
  78. {{ scope.row[param.paramCode] }}
  79. </span>
  80. <span v-if="param.paramCode == 'viewNum'">
  81. <el-tag disable-transitions>
  82. {{
  83. scope.row[param.paramCode] == null
  84. ? "0"
  85. : scope.row[param.paramCode]
  86. }}
  87. </el-tag>
  88. </span>
  89. </template>
  90. </el-table-column>
  91. <el-table-column fixed="right" align="center" label="操作" width="auto">
  92. <template #default="scope">
  93. <!-- <el-button @click="handlerDoc('view', scope.row)">
  94. 预览
  95. </el-button> -->
  96. <el-button type="primary" @click="downloadFile(scope.row)">
  97. 下载
  98. </el-button>
  99. <el-button
  100. type="danger"
  101. @click="deleteServiceFile(scope.row.fileId)"
  102. >
  103. 删除
  104. </el-button>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. <pagination
  109. v-show="table.total > 0"
  110. :total="table.total"
  111. :page.sync="table.query.pageNum"
  112. :limit.sync="table.query.pageSize"
  113. @pagination="getOpenDataList"
  114. />
  115. </el-row>
  116. <el-row type="flex" justify="center">
  117. <!-- <el-button
  118. icon="ArrowLeft"
  119. @click="forwardStep"
  120. circle
  121. ></el-button> -->
  122. <el-button @click="exit">退出</el-button>
  123. <!-- <el-button
  124. icon="ArrowRight"
  125. @click="nextStep"
  126. disabled
  127. circle
  128. ></el-button> -->
  129. </el-row>
  130. <a ref="downloadTools" style="display: none" href="" download=""></a>
  131. </div>
  132. </template>
  133. <script>
  134. import {
  135. getServiceFile,
  136. updateServiceFile,
  137. deleteServiceFile,
  138. } from "@/api/service/serviceFile.js";
  139. import {getToken} from "@/utils/auth";
  140. export default {
  141. name: "serviceFile",
  142. props: ["srvId"],
  143. data() {
  144. return {
  145. uploadUrl: "/pt/service/file/add",
  146. headers: {Authorization: "Bearer " + getToken()},
  147. fileSize: "100",
  148. uploadData: {},
  149. fileTypes: [
  150. "application/vnd.ms-excel",
  151. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  152. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel",
  153. "application/pdf",
  154. "text/xml, application/xml",
  155. "application/xml",
  156. "text/xml",
  157. "application/json",
  158. "text/csv",
  159. ],
  160. table: {
  161. height: window.innerHeight - 430,
  162. list: [],
  163. params: [
  164. {
  165. paramCode: "fileViewname",
  166. paramName: "数据集名称",
  167. align: "left",
  168. width: "200",
  169. },
  170. {
  171. paramCode: "fileType",
  172. paramName: "数据集类型",
  173. width: "100",
  174. },
  175. {
  176. paramCode: "fileSize",
  177. paramName: "数据集大小",
  178. width: "100",
  179. },
  180. {paramCode: "viewNum", paramName: "访问数量/次", width: "90"},
  181. {paramCode: "fileTime", paramName: "提交时间", width: "120"},
  182. ],
  183. total: 0,
  184. query: {
  185. pageNum: 1,
  186. pageSize: 20,
  187. orderBy: "",
  188. data: {
  189. name: "",
  190. },
  191. },
  192. },
  193. };
  194. },
  195. mounted() {
  196. this.getOpenDataList();
  197. },
  198. methods: {
  199. // 前进一步
  200. forwardStep() {
  201. this.$emit("forwardStep");
  202. },
  203. // 后退一步
  204. nextStep() {
  205. this.$emit("nextStep");
  206. },
  207. // 查询帮助数据集表
  208. getOpenDataList() {
  209. if (!this.srvId) {
  210. return;
  211. }
  212. getServiceFile(this.table.query, this.srvId).then((r) => {
  213. this.table.list = r.rows;
  214. this.table.total = r.total;
  215. });
  216. },
  217. // 下载文件
  218. downloadFile(file) {
  219. if (file) {
  220. this.$refs.downloadTools.href = "/doc/files" + file.path;
  221. this.$refs.downloadTools.download = file.name;
  222. this.$refs.downloadTools.click();
  223. }
  224. },
  225. // 删除文件
  226. deleteServiceFile(id) {
  227. deleteServiceFile(id)
  228. .then(() => {
  229. this.$message.success("文件删除成功");
  230. this.getOpenDataList();
  231. })
  232. .catch(() => {
  233. this.$message.error("文件删除失败");
  234. });
  235. },
  236. // 上传前校检格式和大小
  237. handleBeforeUpload(file) {
  238. if (!this.srvId) {
  239. return;
  240. }
  241. this.headers.srvId = this.srvId;
  242. this.uploadData = {srvId: this.srvId};
  243. const pattern = /\.{1}[A-Za-z]{1,}$/;
  244. let fileExt = pattern.exec(file.name);
  245. const checkType = this.fileTypes.includes(file.type);
  246. debugger;
  247. if (!checkType) {
  248. this.$message.warning(
  249. "只能上传 .xls、.xlsx、.json、.xml、.csv 格式的文件!"
  250. );
  251. return false;
  252. }
  253. if (![".xls", ".xlsx"].includes(fileExt[0].toLowerCase())) {
  254. this.$message.warning(
  255. "只能上传 .xls、.xlsx、.json、.xml、.csv 格式的文件!"
  256. );
  257. return false;
  258. }
  259. // 校检文件大小
  260. if (this.fileSize) {
  261. const isLt = file.size / 1024 / 1024 < this.fileSize;
  262. if (!isLt) {
  263. this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
  264. return false;
  265. }
  266. }
  267. return true;
  268. },
  269. // 上传成功后
  270. handleUploadSuccess(res, file) {
  271. this.getOpenDataList();
  272. // // 获取富文本组件实例
  273. // let quill = this.Quill;
  274. // // 如果上传成功
  275. // if (res.code == 200) {
  276. // // 获取光标所在位置
  277. // let length = quill.getSelection().index;
  278. // // 插入图片 res.url为服务器返回的图片地址
  279. // quill.insertEmbed(
  280. // length,
  281. // "image",
  282. // process.env.VUE_APP_BASE_API + res.fileName
  283. // );
  284. // // 调整光标到最后
  285. // quill.setSelection(length + 1);
  286. // } else {
  287. // this.$message.error("文件上传成功");
  288. // }
  289. },
  290. // 文件上传失败
  291. handleUploadError() {
  292. this.$message.error("文件上传失败");
  293. },
  294. // 退出
  295. exit() {
  296. this.$nextTick(() => {
  297. this.$router.replace({
  298. query: {isClose: "true"},
  299. });
  300. });
  301. },
  302. },
  303. watch: {
  304. // 监听 srvId
  305. srvId: {
  306. handler(val) {
  307. if (val) {
  308. this.getOpenDataList();
  309. }
  310. },
  311. immediate: true,
  312. // deep: true,
  313. },
  314. },
  315. };
  316. </script>
  317. <style scoped>
  318. .active {
  319. background: #3785ea;
  320. color: #fff;
  321. border-radius: 2px;
  322. }
  323. </style>