useClassify.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //ppt分类模块
  2. import {ref,reactive} from 'vue'
  3. import { useRouter } from 'vue-router';
  4. import { showToast,showDialog,Dialog } from 'vant';
  5. import {useUserInfo} from '@/hooks/common'
  6. import {pptBtn,enPPTBtn,useAuthBtn} from '@/hooks/useAuthBtn'
  7. const {checkAuthBtn} = useAuthBtn()
  8. const permissionBtn = window.location.pathname.startsWith('/ppten')?enPPTBtn:pptBtn
  9. import {
  10. apiPPTClassify,
  11. apiPPTCatalogueCopy,
  12. apiPPTCatalogueDel,
  13. apiPPTCatalogueRename,
  14. apiPPTDel,
  15. apiPPTShare,
  16. apiPPTCopy
  17. } from '@/api/ppt'
  18. import {useCachedViewsStore} from '@/store/modules/cachedViews'
  19. const cachedViewsStore=useCachedViewsStore()
  20. const userInfo =useUserInfo()
  21. export function useClassify(){
  22. const router=useRouter()
  23. // ppt分类数据
  24. const classifyState = reactive({
  25. privateList:[],
  26. publicList:[],
  27. activeType:['myPPT','pubPPT'],//一级分类是否展开
  28. myActiveType:[],//我的ppt文件夹是否展开
  29. pubActiveType:[],//公共ppt文件夹是否展开
  30. })
  31. // 获取ppt分类数据
  32. const getPPTClassifyData=async()=>{
  33. const res=await apiPPTClassify()
  34. if(res.Ret===200){
  35. const temPriArr=res.Data.PrivateList||[]
  36. classifyState.privateList=temPriArr.map(item=>{
  37. item.PptList=item.PptList?.map(_item=>{
  38. return {
  39. ..._item,
  40. IsSingleShareBoolean:_item.IsSingleShare?true:false
  41. }
  42. })
  43. return item
  44. })
  45. //需求池690 我的PPT分类默认收起
  46. /* classifyState.myActiveType=classifyState.privateList.map(item=>{
  47. return item.GroupId
  48. }) */
  49. classifyState.publicList=res.Data.PublicList||[]
  50. }
  51. }
  52. // 显示目录编辑弹窗
  53. const fileOptState=reactive({
  54. show:false,
  55. data:{},//当前点击的目录数据
  56. showReName:false,//显示重命名弹窗
  57. reNameVal:"",
  58. })
  59. const handleShowFileOpt=e=>{
  60. fileOptState.data=e
  61. fileOptState.reNameVal=e.GroupName
  62. fileOptState.show=true
  63. }
  64. // 复制ppt目录
  65. const handlePPTCatalogueCopy=async()=>{
  66. const res=await apiPPTCatalogueCopy({GroupId:fileOptState.data.GroupId})
  67. if(res.Ret===200){
  68. showToast('复制成功')
  69. getPPTClassifyData()
  70. fileOptState.show=false
  71. }
  72. }
  73. // 删除ppt目录
  74. const handlePPTCatalogueDel=()=>{
  75. if(fileOptState.data.PptList&&fileOptState.data.PptList.length!==0){
  76. showToast('该目录下有关联PPT,不允许删除');
  77. return
  78. }
  79. showDialog({
  80. title: '提示',
  81. message: '删除操作不可恢复,确认删除吗?',
  82. showCancelButton:true
  83. }).then(() => {
  84. // on close
  85. apiPPTCatalogueDel({GroupId:fileOptState.data.GroupId}).then(res=>{
  86. if(res.Ret===200){
  87. getPPTClassifyData()
  88. fileOptState.show=false
  89. }
  90. })
  91. });
  92. }
  93. // 目录重命名
  94. const handlePPTCatalogueReName=async ()=>{
  95. if(!fileOptState.reNameVal){
  96. showToast('请填写目录名称');
  97. return
  98. }
  99. const res=await apiPPTCatalogueRename({
  100. GroupId:fileOptState.data.GroupId,
  101. GroupName:fileOptState.reNameVal
  102. })
  103. if(res.Ret===200){
  104. getPPTClassifyData()
  105. fileOptState.data.GroupName=fileOptState.reNameVal
  106. }
  107. }
  108. // 显示ppt录编辑弹窗
  109. const PPTOptState=reactive({
  110. isCommon:false,//是否为公共ppt目录下的
  111. show:false,
  112. data:{},
  113. showCopy:false,//显示选择复制到目录的弹窗
  114. copyActions:[],//选择复制到目录数
  115. copySelectData:{},//复制选择的目录
  116. })
  117. // e ppt的数据
  118. const handleShowPPTOpt=(e)=>{
  119. PPTOptState.data=e
  120. PPTOptState.isCommon=userInfo.value.AdminId!=e.AdminId?true:false
  121. PPTOptState.show=true
  122. }
  123. // 删除ppt
  124. // back 则返回上一级
  125. const handlePPTDel=({back})=>{
  126. showDialog({
  127. title: '提示',
  128. message: '删除操作不可恢复,若该PPT被共享,则同步删除共享PPT,确认删除吗?',
  129. showCancelButton:true
  130. }).then(() => {
  131. // on close
  132. apiPPTDel({PptId:PPTOptState.data.PptId}).then(res=>{
  133. if(res.Ret===200){
  134. if(back){
  135. router.back()
  136. }
  137. getPPTClassifyData()
  138. PPTOptState.show=false
  139. }
  140. }).catch(()=>{})
  141. });
  142. }
  143. //设置ppt是否共享
  144. const handlePPTShare=async (e)=>{
  145. const res=await apiPPTShare({
  146. PptId:PPTOptState.data.PptId
  147. })
  148. if(res.Ret===200){
  149. getPPTClassifyData()
  150. PPTOptState.data.IsSingleShareBoolean=e
  151. }
  152. }
  153. // 显示复制ppt选择目录弹窗
  154. // 如果是详情页中调用则会传一个pptid
  155. const handleShowPPTCopy=({pptid})=>{
  156. PPTOptState.copyActions=classifyState.privateList.map(item=>{
  157. return {
  158. text:item.GroupName,
  159. ...item
  160. }
  161. })
  162. console.log(pptid);
  163. if(pptid){
  164. PPTOptState.data.PptId=Number(pptid)
  165. }
  166. PPTOptState.showCopy=true
  167. }
  168. // 保存 复制ppt
  169. const handlePPTCopy=()=>{
  170. if(!PPTOptState.copySelectData.GroupId){
  171. showToast('请选择目录');
  172. return
  173. }
  174. apiPPTCopy({
  175. PptId:PPTOptState.data.PptId,
  176. GroupId:PPTOptState.copySelectData.GroupId
  177. }).then(res=>{
  178. if(res.Ret===200){
  179. setTimeout(() => {
  180. showToast('复制成功');
  181. }, 100);
  182. getPPTClassifyData()
  183. PPTOptState.showCopy=false
  184. }
  185. })
  186. }
  187. // 关闭复制ppt选择目录弹窗钩子函数
  188. const handlePPTCopyBeforeClose=(action)=>{
  189. console.log(action);
  190. if(action==='confirm'&&!PPTOptState.copySelectData.GroupId){
  191. return false
  192. }else{
  193. return true
  194. }
  195. }
  196. // 跳转ppt详情
  197. const goPPTDetail=async (e)=>{
  198. await cachedViewsStore.removeCaches('PPTDetail')
  199. if(window.location.pathname.startsWith('/ppten')){
  200. router.push({
  201. path:"/ppten/detail",
  202. query:{
  203. id:e.PptId
  204. }
  205. })
  206. }else{
  207. router.push({
  208. path:"/ppt/detail",
  209. query:{
  210. id:e.PptId
  211. }
  212. })
  213. }
  214. }
  215. return {
  216. classifyState,
  217. getPPTClassifyData,
  218. fileOptState,
  219. handleShowFileOpt,
  220. handlePPTCatalogueCopy,
  221. handlePPTCatalogueDel,
  222. handlePPTCatalogueReName,
  223. PPTOptState,
  224. handleShowPPTOpt,
  225. handlePPTDel,
  226. handlePPTShare,
  227. handleShowPPTCopy,
  228. handlePPTCopy,
  229. handlePPTCopyBeforeClose,
  230. goPPTDetail,
  231. permissionBtn,
  232. checkAuthBtn
  233. }
  234. }