index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="upload">
  3. <!--头部操作-->
  4. <!-- <Header>
  5. <save type="save" @click.native="save()"></save>
  6. </Header>-->
  7. <el-row>
  8. <el-col :span="14" v-if="$route.path === '/upload_archives'">
  9. <!--标题 分类-->
  10. <Set ref="set" @setSelectChange="selectChange" @setTitleChange="titleChange" />
  11. <!--文件列表-->
  12. <file-list ref="attFileList" v-if="uploadType == '1' || uploadType == '2'">
  13. <upload slot="upload" @onSuccess="onSuccess" target="archives" :classType="uploadType"></upload>
  14. <template v-slot:delete="scope">
  15. <delete1 @deleteFile="deleteFile" :obj="scope.data"></delete1>
  16. </template>
  17. <template v-slot:download="scope">
  18. <download :data="scope.data"></download>
  19. </template>
  20. </file-list>
  21. <!--富文本-->
  22. <file-text ref="text" v-if="uploadType == '3'">
  23. <Editor
  24. ref="editor"
  25. slot="editor"
  26. :content="cacheInfo.content.content"
  27. :id="uploadCacheData.sat_sharematerialid"
  28. ></Editor>
  29. </file-text>
  30. </el-col>
  31. <el-col :span="24" v-else>
  32. <!--标题 分类-->
  33. <Set ref="set" @setSelectChange="selectChange" @setTitleChange="titleChange" />
  34. <!--文件列表-->
  35. <file-list ref="attFileList" v-if="uploadType == '1' || uploadType == '2'">
  36. <upload slot="upload" @onSuccess="onSuccess" target="archives" :classType="uploadType"></upload>
  37. <template v-slot:delete="scope">
  38. <delete1 @deleteFile="deleteFile" :obj="scope.data"></delete1>
  39. </template>
  40. <template v-slot:download="scope">
  41. <download :data="scope.data"></download>
  42. </template>
  43. </file-list>
  44. <!--富文本-->
  45. <file-text ref="text" v-if="uploadType == '3'">
  46. <Editor
  47. ref="editor"
  48. slot="editor"
  49. :content="cacheInfo.content.content"
  50. :id="uploadCacheData.sat_sharematerialid"
  51. ></Editor>
  52. </file-text>
  53. </el-col>
  54. <!-- 授权范围 -->
  55. <el-col :span="10" v-if="$route.path === '/upload_archives'">
  56. <scopeOfauth
  57. style="margin-left:10px;"
  58. :defaultData="defaultData"
  59. :dataid="authId"
  60. :disabled="false"
  61. obiectName="sat_sharematerialid"
  62. @onChecked="onChecked"
  63. />
  64. </el-col>
  65. </el-row>
  66. <div class="fixed__btn__panel">
  67. <el-button size="small" @click="$store.dispatch('DrawerShowChange',false)" class="normal-btn-width">取 消</el-button>
  68. <el-button size="small" :type="$route.query.type === '1' ?'warning':'primary'" @click="save" class="normal-btn-width">{{$route.query.type === '1' ?'保 存' : '确 定'}}</el-button>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import scopeOfauth from '@/components/scopeOfAuthority/index.vue'
  74. import Header from '@/SManagement/archives_upload/components/Header'
  75. import Set from '@/SManagement/archives_upload/components/Set'
  76. import FileList from '@/SManagement/archives_upload/components/FileList'
  77. import FileText from '@/SManagement/archives_upload/components/FileText'
  78. import upload from '@/SManagement/archives_upload/components/upload'
  79. import save from '@/SManagement/archives_upload/components/save'
  80. import reset from '@/SManagement/archives_upload/components/reset'
  81. import delete1 from '@/SManagement/archives_upload/components/delete'
  82. import download from '@/SManagement/archives_upload/components/download'
  83. import Editor from '@/components/my-editor/Editor'
  84. import removeFile from '@/utils/removeFile'
  85. import { log } from '@antv/g2plot/lib/utils'
  86. export default {
  87. name: 'index',
  88. data () {
  89. return {
  90. //新增请求配置
  91. cacheInfo: {
  92. "classname": "webmanage.saletool.sharematerial.sharematerial",
  93. "method": "insertOrUpdate",
  94. "content": {
  95. "title": "",
  96. "sat_sharematerial_classid": 9999,
  97. "notes": "",
  98. "tag": [],
  99. "isonlymanager_dept":0,
  100. "canfiledownload": 1,
  101. "content": "",
  102. "sat_sharematerialid": 0,
  103. "type": ''
  104. }
  105. },
  106. //上传的初始数据
  107. uploadCacheData: {},
  108. //创建素材模板的id
  109. create_sat_sharematerialid: 0,
  110. uploadType: null,
  111. /* 授权使用 */
  112. defaultData: {},
  113. authData: {},
  114. authId: 0,
  115. }
  116. },
  117. components: {
  118. Header,
  119. Set,
  120. FileList,
  121. FileText,
  122. upload,
  123. save,
  124. reset,
  125. delete1,
  126. download,
  127. Editor,
  128. scopeOfauth
  129. },
  130. computed: {
  131. },
  132. watch: {
  133. $route () {
  134. this.uploadData()
  135. }
  136. },
  137. mounted () {
  138. //获取上传模板
  139. this.uploadData()
  140. },
  141. beforeDestroy () {
  142. // this.removeAllData()
  143. },
  144. methods: {
  145. //获取素材模板
  146. uploadData () {
  147. setTimeout(() => {
  148. let data = JSON.parse(window.sessionStorage.getItem("newMaterial"))
  149. console.log(data);
  150. this.cacheInfo.content.sat_sharematerialid = data.sat_sharematerialid
  151. this.cacheInfo.content.title = data.title
  152. this.cacheInfo.content.sat_sharematerial_classid = data.sat_sharematerial_classid
  153. this.cacheInfo.content.content = data.content
  154. this.uploadType = data.type
  155. this.$refs.set.ruleForm.title = data.title
  156. this.$refs.set.ruleForm.category = data.sat_sharematerial_classid
  157. this.uploadCacheData.sat_sharematerialid = data.sat_sharematerialid
  158. this.uploadCacheData.attinfos = data.attinfos
  159. this.authId = this.$route.query.id
  160. setTimeout(this.randerData, 100)
  161. if (data.title != '') this.uploadCacheData.status = "完成"
  162. this.query_auth()
  163. },100)
  164. },
  165. /* 更新附件列表数据 */
  166. randerData () {
  167. if (this.uploadType != 3) this.$refs.attFileList.randerData(this.uploadCacheData.attinfos)
  168. },
  169. deleteFile (id) {
  170. this.uploadCacheData.attinfos = this.uploadCacheData.attinfos.filter(v => v.linksid != id)
  171. this.randerData()
  172. },
  173. //保存
  174. save () {
  175. this.$refs.set.$refs.form.validate((val) => {
  176. if (val) {
  177. //判断有无内容
  178. if (this.uploadType == '3') {
  179. const content = this.$refs.editor.editor.getHtml()
  180. if (content == "<p><br></p>") return this.$message.error('您还未编辑图文内容')
  181. this.cacheInfo.content.content = content
  182. } else {
  183. if (this.uploadCacheData.attinfos.length == 0) return this.$message.error('您还未上传附件')
  184. }
  185. this.cacheInfo.content.type = this.uploadType
  186. console.log(this.cacheInfo);
  187. //判断所属ID是否为初始ID
  188. if (this.cacheInfo.content.sat_sharematerial_classid == '9999' + JSON.parse(window.sessionStorage.getItem("active_account")).userid) return this.$message.error('请选择素材分类')
  189. this.$api.requested(this.cacheInfo).then(res => {
  190. this.tool.showMessage(res, () => {
  191. this.uploadCacheData.status = '完成'
  192. if (this.$route.path === '/upload_archives'){
  193. this.insertCoursewareauth()
  194. }
  195. this.$store.dispatch('DrawerShowChange',false)
  196. this.$router.back()
  197. this.$emit('onSuccess')
  198. })
  199. })
  200. } else {
  201. this.$notify({
  202. title: '提示',
  203. message: '请输入标题或分类',
  204. type: 'error'
  205. })
  206. }
  207. })
  208. },
  209. // 查询授权信息
  210. async query_auth () {
  211. const res = await this.$api.requested({
  212. "classname": "webmanage.saletool.sharematerial.sharematerialAuth",
  213. "method": "selectAuth",
  214. "content": {
  215. "sat_sharematerialid": this.uploadCacheData.sat_sharematerialid,
  216. }
  217. })
  218. this.defaultData = res.data
  219. },
  220. // 新增授权范围
  221. async insertCoursewareauth () {
  222. let p = {
  223. "classname": "webmanage.saletool.sharematerial.sharematerialAuth",
  224. "method": "insertOrUpdate",
  225. "content": this.authData
  226. }
  227. const res = await this.$api.requested(p)
  228. res.code === 0 ? this.$notify({
  229. title: '失败',
  230. message: res.data,
  231. type: 'error'
  232. }) : ''
  233. },
  234. // 获取保存授权范围数据
  235. onChecked (param) {
  236. this.authData = param
  237. },
  238. //文件上传成功
  239. async onSuccess (id) {
  240. console.log(id)
  241. let param = {
  242. "classname": "system.attachment.Attachment",
  243. "method": "createFileLink",
  244. "content": {
  245. "ownertable": "SAT_SHAREMATERIAL",
  246. "ownerid": this.uploadCacheData.sat_sharematerialid,
  247. "usetype": "default",
  248. "attachmentids": [id]
  249. }
  250. }
  251. let res = await this.$api.requested(param)
  252. if (res.msg != '成功') return this.$notify({
  253. title: '提示',
  254. message: '上传失败',
  255. type: 'error'
  256. })
  257. this.uploadCacheData.attinfos = this.uploadCacheData.attinfos.concat(res.data)
  258. this.randerData()
  259. },
  260. //退出后对数据进行销毁
  261. async removeAllData () {
  262. if (this.$route.params.data) {
  263. this.uploadCacheData.status = "新建"
  264. this.uploadCacheData.sat_sharematerialid = this.create_sat_sharematerialid
  265. }
  266. if (this.uploadCacheData.status == '新建') {
  267. let attinfos = this.uploadCacheData.attinfos
  268. //删除附件
  269. removeFile.removeFileList(attinfos)
  270. //删除素材
  271. let param = {
  272. "classname": "webmanage.saletool.sharematerial.sharematerial",
  273. "method": "delete",
  274. "content": {
  275. "sat_sharematerialid": [this.uploadCacheData.sat_sharematerialid]
  276. }
  277. }
  278. let result = await this.$api.requested(param)
  279. }
  280. },
  281. //重置所有数据
  282. reSetAllData () {
  283. this.cacheInfo.content.title = ''
  284. this.cacheInfo.content.sat_sharematerial_classid = ''
  285. this.$refs.editor.html = ''
  286. this.$refs.set.ruleForm.title = ''
  287. this.$refs.set.ruleForm.category = ''
  288. this.uploadCacheData.attinfos = []
  289. },
  290. /* set组件 分类选择回调 */
  291. selectChange (id) {
  292. this.cacheInfo.content.sat_sharematerial_classid = id
  293. },
  294. /* set组件 title填写回调 */
  295. titleChange (name) {
  296. this.cacheInfo.content.title = name
  297. },
  298. },
  299. };
  300. </script>
  301. <style scoped>
  302. .mandate {
  303. width: 732px;
  304. height: 500px;
  305. background: #fff;
  306. margin-left: 16px;
  307. }
  308. </style>