index.vue 8.6 KB

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