scriptFile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <style>
  2. #wps-iframe {
  3. height: 100%;
  4. }
  5. </style>
  6. <template>
  7. <a-card :bordered="false">
  8. <!-- 查询区域 -->
  9. <div class="table-page-search-wrapper">
  10. <a-form layout="inline">
  11. <a-row :gutter="24">
  12. <a-col :md="6" :sm="8">
  13. <selectTable :projectId.sync="queryParam.projectId"></selectTable>
  14. </a-col>
  15. <a-col :md="6" :sm="8">
  16. <a-form-item label="脚本名称">
  17. <a-input placeholder="请输入脚本名称" v-model="queryParam.name"></a-input>
  18. </a-form-item>
  19. </a-col>
  20. <a-col :md="6" :sm="8">
  21. <a-form-item label="创建人">
  22. <a-select
  23. v-model="queryParam.creator"
  24. showSearch
  25. allowClear
  26. placeholder="请选择创建人"
  27. optionFilterProp="children"
  28. style="width: 100%"
  29. :filterOption="true"
  30. @search="search"
  31. @focus="getAllUserList"
  32. >
  33. <a-select-option
  34. v-for="appModel in options"
  35. :key="appModel.userId + new Date().getTime()"
  36. :value="appModel.userId"
  37. >
  38. {{ appModel.realName }}
  39. &#12288;&#12288;{{ appModel.roleName }}
  40. </a-select-option>
  41. </a-select>
  42. </a-form-item>
  43. </a-col>
  44. <a-col :md="6" :sm="8">
  45. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  46. <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
  47. <a-button
  48. type="primary"
  49. @click="searchReset"
  50. icon="reload"
  51. style="margin-left: 8px"
  52. >重置</a-button>
  53. </span>
  54. </a-col>
  55. </a-row>
  56. </a-form>
  57. </div>
  58. <div style="float:right;margin:0 0 20px 20px">
  59. <!-- <a-upload
  60. name="file"
  61. :multiple="false"
  62. :action="uploadAction"
  63. :headers="tokenHeader"
  64. :showUploadList="false"
  65. :beforeUpload="beforeUpload"
  66. @change="handleChange"
  67. style="margin-right:20px"
  68. >
  69. <a-button :disabled="loadingElse">
  70. <a-icon type="upload" />
  71. {{loadingElse?'上传中,请稍后':'文件上传'}}
  72. </a-button>
  73. </a-upload> -->
  74. <a-dropdown placement="bottomRight">
  75. <a-button>新增</a-button>
  76. <a-menu slot="overlay">
  77. <a-menu-item>
  78. <a-icon type="file-word" />
  79. <span style="text-align: center" @click="creatWps('word')">文字文档</span>
  80. </a-menu-item>
  81. <a-menu-item>
  82. <a-icon type="file-excel" />
  83. <span style="text-align: center" @click="creatWps('excel')">表格文档</span>
  84. </a-menu-item>
  85. <a-menu-item>
  86. <a-icon type="file-ppt" />
  87. <span style="text-align: center" @click="creatWps('ppt')">演示文档</span>
  88. </a-menu-item>
  89. </a-menu>
  90. </a-dropdown>
  91. </div>
  92. <div style="clear:both"></div>
  93. <div>
  94. <a-table
  95. ref="table"
  96. size="middle"
  97. bordered
  98. rowKey="name"
  99. :columns="columns"
  100. :dataSource="dataSource"
  101. :pagination="ipagination"
  102. :loading="loading"
  103. @change="handleTableChange"
  104. >
  105. <span slot="modifyTime" slot-scope="text">{{text|getDate}}</span>
  106. <span slot="size" slot-scope="text">{{text|sizeShow}}</span>
  107. <span slot="projectId_dictText" slot-scope="text">{{text?text:'-'}}</span>
  108. <span slot="action" slot-scope="text, record">
  109. <a @click="getViewUrlDbPath(record)">编辑</a>
  110. <a-divider type="vertical" />
  111. <a @click="bindProject(record)">项目绑定</a>
  112. <a-divider type="vertical" />
  113. <a @click="downLoad(record)">下载</a>
  114. <a-divider type="vertical" />
  115. <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
  116. <a>删除</a>
  117. </a-popconfirm>
  118. </span>
  119. </a-table>
  120. </div>
  121. <div id="show"></div>
  122. <a-modal
  123. :maskClosable="false"
  124. :title="type=='add'?'脚本新建':'脚本编辑'"
  125. v-model="visibleBind"
  126. :width="1200"
  127. :footer="null"
  128. >
  129. <iframe :src="src" frameborder="0" style="width:100%;height:600px" v-if="type=='add'"></iframe>
  130. <div id="showWps" style="height:600px" v-show="type=='edit'"></div>
  131. </a-modal>
  132. <a-modal :maskClosable="false" title="绑定项目" v-model="visibleProject" @ok="handleOk">
  133. <span>项目选择:</span>
  134. <a-select
  135. v-model="projectId"
  136. showSearch
  137. style="width:300px"
  138. optionFilterProp="children"
  139. :filterOption="filterOption"
  140. >
  141. <a-select-option :value="item.projectId" v-for="item of dataElse" :key="item.id">
  142. {{ item.projectName }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{
  143. item.mediaId == "1" ? '头条' :item.mediaId == "2"? '快手':item.mediaId == "3"?'头条内广':'快手内广'
  144. }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.advertiserName }}
  145. </a-select-option>
  146. </a-select>
  147. </a-modal>
  148. <!-- table区域-end -->
  149. <!-- 表单区域 -->
  150. <wpsFile-modal ref="modalForm" @ok="modalFormOk"></wpsFile-modal>
  151. </a-card>
  152. </template>
  153. <script>
  154. import { getAction, postAction, postFile, deleteAction, putAction } from '@/api/manage'
  155. import selectTable from '@/views/modules/Statistics/components/selectPagination.vue'
  156. import WpsFileModal from './modules/WpsFileModal'
  157. import { mapGetters } from 'vuex'
  158. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  159. import qs from 'qs'
  160. const fileSuffix = [
  161. 'xls',
  162. 'xlt',
  163. 'et',
  164. 'xlsx',
  165. 'xltx',
  166. 'csv',
  167. 'xlsm',
  168. 'xltm',
  169. 'doc',
  170. 'dot',
  171. 'wps',
  172. 'wpt',
  173. 'docx',
  174. 'dotx',
  175. 'docm',
  176. 'dotm',
  177. 'ppt',
  178. 'pptx',
  179. 'pptm',
  180. 'ppsx',
  181. 'ppsm',
  182. 'pps',
  183. 'potx',
  184. 'potm',
  185. 'dpt',
  186. 'dps',
  187. 'pdf',
  188. ]
  189. export default {
  190. name: 'WpsFileList',
  191. mixins: [JeecgListMixin],
  192. components: {
  193. WpsFileModal,
  194. selectTable,
  195. },
  196. data() {
  197. return {
  198. description: 'wps文件管理页面',
  199. dataElse: [],
  200. projectId: '',
  201. visibleProject: false,
  202. // 表头
  203. visibleBind: false,
  204. wpsType: 'word',
  205. type: 'add',
  206. uploadAction: 'http://api.tjyourong.com.cn/jeecg-boot/ctop/wpsFile/uploadFile',
  207. columns: [
  208. {
  209. title: '文件名称',
  210. align: 'center',
  211. dataIndex: 'name',
  212. },
  213. {
  214. title: '文件大小(KB)',
  215. align: 'center',
  216. dataIndex: 'size',
  217. scopedSlots: {
  218. customRender: 'size',
  219. },
  220. },
  221. {
  222. title: '绑定项目',
  223. align: 'center',
  224. dataIndex: 'projectId_dictText',
  225. scopedSlots: {
  226. customRender: 'projectId_dictText',
  227. },
  228. },
  229. {
  230. title: '创建人',
  231. align: 'center',
  232. dataIndex: 'creator_dictText',
  233. },
  234. {
  235. title: '发布时间',
  236. align: 'center',
  237. dataIndex: 'modifyTime',
  238. scopedSlots: {
  239. customRender: 'modifyTime',
  240. },
  241. },
  242. {
  243. title: '操作',
  244. dataIndex: 'action',
  245. align: 'center',
  246. scopedSlots: {
  247. customRender: 'action',
  248. },
  249. },
  250. ],
  251. url: {
  252. list: '/ctop/wpsFile/list',
  253. delete: '/ctop/wpsFile/delete',
  254. deleteBatch: '/ctop/wpsFile/deleteBatch',
  255. exportXlsUrl: 'ctop/wpsFile/exportXls',
  256. importExcelUrl: 'ctop/wpsFile/importExcel',
  257. },
  258. src: '',
  259. loadingElse: false,
  260. fileId: '',
  261. loadingOk: false,
  262. options: [],
  263. }
  264. },
  265. computed: {
  266. importExcelUrl: function () {
  267. return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
  268. },
  269. },
  270. watch: {
  271. visibleBind(n, o) {
  272. if (!n) {
  273. this.src = ''
  274. this.loadData(1)
  275. }
  276. },
  277. },
  278. filters: {
  279. getDate(value) {
  280. let date = new Date(value)
  281. let y = date.getFullYear()
  282. let MM = date.getMonth() + 1
  283. MM = MM < 10 ? '0' + MM : MM
  284. let d = date.getDate()
  285. d = d < 10 ? '0' + d : d
  286. return y + '-' + MM + '-' + d
  287. },
  288. sizeShow(value) {
  289. return (value / 1024).toFixed(2)
  290. },
  291. },
  292. mounted() {
  293. this.getParticipateList()
  294. // getAction('/sys/user/getAllUserList', '').then((res) => {
  295. // if (res.success) {
  296. // this.options = res.result
  297. // }
  298. // })
  299. },
  300. methods: {
  301. search(value) {
  302. this.options = []
  303. if (value != '') {
  304. // this.options = this.list.filter(item => {
  305. // var data = item.realName + ' ' + item.roleName
  306. // return data.toLowerCase().indexOf(value.toLowerCase()) > -1
  307. // })
  308. // this.options = [...this.options]
  309. this.getAllUserList(value)
  310. } else {
  311. this.getAllUserList()
  312. }
  313. },
  314. getAllUserList(value) {
  315. getAction('/sys/user/getAllUserList', { pageSize: 50, pageNo: 1, userName: value }).then((res) => {
  316. if (res.success) {
  317. this.options = res.result.list
  318. }
  319. })
  320. },
  321. downLoad(item) {
  322. let downloadElement = document.createElement('a')
  323. downloadElement.href = item.downloadUrl
  324. downloadElement.download = item.name //下载后文件名
  325. document.body.appendChild(downloadElement)
  326. downloadElement.click() //点击下载
  327. document.body.removeChild(downloadElement) //下载完成移除元素
  328. },
  329. filterOption(input, option) {
  330. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  331. },
  332. ...mapGetters(['nickname', 'avatar', 'userInfo']),
  333. getParticipateList() {
  334. getAction('/ctop/projectMember/participateList', {
  335. userId: this.userInfo().id,
  336. }).then((res) => {
  337. if (res.code == 0) {
  338. this.dataElse = res.result
  339. }
  340. })
  341. },
  342. beforeUpload(file) {
  343. this.loadingElse = true
  344. const size = (Number(file.size) / (1024 * 1024)).toFixed(2)
  345. const fileName = file.name
  346. const fileStrArr = fileName.split('.')
  347. const suffix = fileStrArr[fileStrArr.length - 1]
  348. let result = fileSuffix.some((item) => {
  349. return item === suffix
  350. })
  351. if (!result) {
  352. this.$message.error('不支持该文件类型')
  353. this.loadingElse = false
  354. return false
  355. }
  356. if (size > 10) {
  357. this.$message.error('文件不能大于10MB')
  358. this.loadingElse = false
  359. return false
  360. }
  361. },
  362. handleChange(info) {
  363. if (info.file.status !== 'uploading') {
  364. console.log(info.file, info.fileList)
  365. }
  366. if (info.file.status === 'done') {
  367. this.$message.success(`${info.file.name} 上传成功`)
  368. this.loadingElse = false
  369. this.loadData(1)
  370. } else if (info.file.status === 'error') {
  371. this.$message.error(`${info.file.name} file upload failed.`)
  372. this.loadingElse = false
  373. }
  374. },
  375. handleOk(e) {
  376. this.loadingOk = true
  377. var params = qs.stringify({
  378. projectId: this.projectId,
  379. fileId: this.fileId,
  380. })
  381. postAction('/ctop/wpsFile/bindProject', params).then((res) => {
  382. if (res.success) {
  383. this.visibleProject = false
  384. this.projectId = ''
  385. this.loadingOk = false
  386. this.loadData()
  387. } else {
  388. this.$message.error('绑定失败')
  389. this.loadingOk = false
  390. }
  391. })
  392. },
  393. creatWps(type) {
  394. console.log(type)
  395. this.visibleBind = true
  396. this.wpsType = type
  397. this.type = 'add'
  398. getAction('/ctop/wpsFile/createTemplateFile', {
  399. template: type,
  400. }).then((res) => {
  401. console.log(res)
  402. if (res.code == 200) {
  403. this.src = res.msg
  404. console.log(this.src)
  405. } else {
  406. this.$message.error('请求错误!')
  407. }
  408. })
  409. // getCreateFilePath({
  410. // template: type
  411. // }).then(res => {
  412. // console.log(res)
  413. // // if (res.data.data){
  414. // this.src = res.data.msg;
  415. // // }else {
  416. // // this.showErrMeg('请求错误!');
  417. // // }
  418. // }).catch(() => {
  419. // this.showErrMeg('请求错误!');
  420. // });
  421. },
  422. bindProject(item) {
  423. this.visibleProject = true
  424. this.projectId = ''
  425. this.fileId = item.id
  426. // this.getParticipateList()
  427. },
  428. getViewUrlDbPath(item) {
  429. // this.loading = true;
  430. const params = {
  431. fileId: item.id,
  432. userId: item.creator,
  433. }
  434. getAction('/v1/api/file/getViewUrlDbPath', params).then((res) => {
  435. console.log(res)
  436. if (res.data) {
  437. let r = res.data
  438. this.visibleBind = true
  439. // this.src = r.wpsUrl;
  440. this.type = 'edit'
  441. this.openWps(r.wpsUrl, r.token)
  442. } else {
  443. this.$message.error('请求错误')
  444. }
  445. })
  446. },
  447. openWps(url, token) {
  448. this.$nextTick(() => {
  449. let _this = this
  450. const wps = _this.wps.config({
  451. mode: 'simple',
  452. mount: document.querySelector('#showWps'),
  453. wpsUrl: url,
  454. })
  455. wps.setToken({
  456. token: token,
  457. })
  458. let app = wps.Application
  459. })
  460. },
  461. },
  462. }
  463. </script>
  464. <style scoped>
  465. @import '~@assets/less/common.less';
  466. </style>