index.vue 8.8 KB

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