123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- //ppt分类模块
- import {ref,reactive} from 'vue'
- import { useRouter } from 'vue-router';
- import { showToast,showDialog,Dialog } from 'vant';
- import {useUserInfo} from '@/hooks/common'
- import {pptBtn,enPPTBtn,useAuthBtn} from '@/hooks/useAuthBtn'
- const {checkAuthBtn} = useAuthBtn()
- const permissionBtn = window.location.pathname.startsWith('/ppten')?enPPTBtn:pptBtn
- import {
- apiPPTClassify,
- apiPPTCatalogueCopy,
- apiPPTCatalogueDel,
- apiPPTCatalogueRename,
- apiPPTDel,
- apiPPTShare,
- apiPPTCopy
- } from '@/api/ppt'
- import {useCachedViewsStore} from '@/store/modules/cachedViews'
- const cachedViewsStore=useCachedViewsStore()
- const userInfo =useUserInfo()
- export function useClassify(){
- const router=useRouter()
- // ppt分类数据
- const classifyState = reactive({
- privateList:[],
- publicList:[],
- activeType:['myPPT','pubPPT'],//一级分类是否展开
- myActiveType:[],//我的ppt文件夹是否展开
- pubActiveType:[],//公共ppt文件夹是否展开
- })
- // 获取ppt分类数据
- const getPPTClassifyData=async()=>{
- const res=await apiPPTClassify()
- if(res.Ret===200){
- const temPriArr=res.Data.PrivateList||[]
- classifyState.privateList=temPriArr.map(item=>{
- item.PptList=item.PptList?.map(_item=>{
- return {
- ..._item,
- IsSingleShareBoolean:_item.IsSingleShare?true:false
- }
- })
- return item
- })
- //需求池690 我的PPT分类默认收起
- /* classifyState.myActiveType=classifyState.privateList.map(item=>{
- return item.GroupId
- }) */
- classifyState.publicList=res.Data.PublicList||[]
- }
- }
- // 显示目录编辑弹窗
- const fileOptState=reactive({
- show:false,
- data:{},//当前点击的目录数据
- showReName:false,//显示重命名弹窗
- reNameVal:"",
- })
- const handleShowFileOpt=e=>{
- fileOptState.data=e
- fileOptState.reNameVal=e.GroupName
- fileOptState.show=true
- }
- // 复制ppt目录
- const handlePPTCatalogueCopy=async()=>{
- const res=await apiPPTCatalogueCopy({GroupId:fileOptState.data.GroupId})
- if(res.Ret===200){
- showToast('复制成功')
- getPPTClassifyData()
- fileOptState.show=false
- }
- }
- // 删除ppt目录
- const handlePPTCatalogueDel=()=>{
- if(fileOptState.data.PptList&&fileOptState.data.PptList.length!==0){
- showToast('该目录下有关联PPT,不允许删除');
- return
- }
- showDialog({
- title: '提示',
- message: '删除操作不可恢复,确认删除吗?',
- showCancelButton:true
- }).then(() => {
- // on close
- apiPPTCatalogueDel({GroupId:fileOptState.data.GroupId}).then(res=>{
- if(res.Ret===200){
- getPPTClassifyData()
- fileOptState.show=false
- }
- })
- });
- }
- // 目录重命名
- const handlePPTCatalogueReName=async ()=>{
- if(!fileOptState.reNameVal){
- showToast('请填写目录名称');
- return
- }
- const res=await apiPPTCatalogueRename({
- GroupId:fileOptState.data.GroupId,
- GroupName:fileOptState.reNameVal
- })
- if(res.Ret===200){
- getPPTClassifyData()
- fileOptState.data.GroupName=fileOptState.reNameVal
- }
- }
- // 显示ppt录编辑弹窗
- const PPTOptState=reactive({
- isCommon:false,//是否为公共ppt目录下的
- show:false,
- data:{},
- showCopy:false,//显示选择复制到目录的弹窗
- copyActions:[],//选择复制到目录数
- copySelectData:{},//复制选择的目录
-
- })
- // e ppt的数据
- const handleShowPPTOpt=(e)=>{
- PPTOptState.data=e
- PPTOptState.isCommon=userInfo.value.AdminId!=e.AdminId?true:false
- PPTOptState.show=true
- }
- // 删除ppt
- // back 则返回上一级
- const handlePPTDel=({back})=>{
- showDialog({
- title: '提示',
- message: '删除操作不可恢复,若该PPT被共享,则同步删除共享PPT,确认删除吗?',
- showCancelButton:true
- }).then(() => {
- // on close
- apiPPTDel({PptId:PPTOptState.data.PptId}).then(res=>{
- if(res.Ret===200){
- if(back){
- router.back()
- }
- getPPTClassifyData()
- PPTOptState.show=false
- }
- }).catch(()=>{})
- });
- }
- //设置ppt是否共享
- const handlePPTShare=async (e)=>{
- const res=await apiPPTShare({
- PptId:PPTOptState.data.PptId
- })
- if(res.Ret===200){
- getPPTClassifyData()
- PPTOptState.data.IsSingleShareBoolean=e
- }
- }
- // 显示复制ppt选择目录弹窗
- // 如果是详情页中调用则会传一个pptid
- const handleShowPPTCopy=({pptid})=>{
- PPTOptState.copyActions=classifyState.privateList.map(item=>{
- return {
- text:item.GroupName,
- ...item
- }
- })
- console.log(pptid);
- if(pptid){
- PPTOptState.data.PptId=Number(pptid)
- }
- PPTOptState.showCopy=true
- }
- // 保存 复制ppt
- const handlePPTCopy=()=>{
- if(!PPTOptState.copySelectData.GroupId){
- showToast('请选择目录');
- return
- }
-
- apiPPTCopy({
- PptId:PPTOptState.data.PptId,
- GroupId:PPTOptState.copySelectData.GroupId
- }).then(res=>{
- if(res.Ret===200){
- setTimeout(() => {
- showToast('复制成功');
- }, 100);
-
- getPPTClassifyData()
- PPTOptState.showCopy=false
- }
- })
- }
- // 关闭复制ppt选择目录弹窗钩子函数
- const handlePPTCopyBeforeClose=(action)=>{
- console.log(action);
- if(action==='confirm'&&!PPTOptState.copySelectData.GroupId){
- return false
- }else{
- return true
- }
- }
- // 跳转ppt详情
- const goPPTDetail=async (e)=>{
- await cachedViewsStore.removeCaches('PPTDetail')
- if(window.location.pathname.startsWith('/ppten')){
- router.push({
- path:"/ppten/detail",
- query:{
- id:e.PptId
- }
- })
- }else{
- router.push({
- path:"/ppt/detail",
- query:{
- id:e.PptId
- }
- })
- }
- }
- return {
- classifyState,
- getPPTClassifyData,
- fileOptState,
- handleShowFileOpt,
- handlePPTCatalogueCopy,
- handlePPTCatalogueDel,
- handlePPTCatalogueReName,
- PPTOptState,
- handleShowPPTOpt,
- handlePPTDel,
- handlePPTShare,
- handleShowPPTCopy,
- handlePPTCopy,
- handlePPTCopyBeforeClose,
- goPPTDetail,
- permissionBtn,
- checkAuthBtn
- }
- }
|