index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="share-wrapper">
  3. <div class="share-file-wrapper" v-if="shareStep === 3">
  4. <div class="operation-wrapper">
  5. <!-- 面包屑导航栏 -->
  6. <BreadCrumb class="breadcrumb" :fileType="7"></BreadCrumb>
  7. <el-button type="primary" size="mini" icon="el-icon-takeaway-box" @click="handleSaveBtnClick"
  8. >保存到网盘</el-button
  9. >
  10. </div>
  11. <!-- 文件列表-表格模式 -->
  12. <FileTable
  13. ref="fileTableInstance"
  14. :fileType="7"
  15. :filePath="filePath"
  16. :fileList="fileList"
  17. :loading="loading"
  18. @setSelectionFile="setSelectionFile"
  19. ></FileTable>
  20. </div>
  21. <!-- 文件分享对话框 -->
  22. <el-dialog
  23. title="文件分享"
  24. :visible.sync="dialogShareFile.visible"
  25. :show-close="false"
  26. :close-on-click-modal="false"
  27. :close-on-press-escape="false"
  28. width="500px"
  29. >
  30. <div class="end-time" v-if="shareStep === 1">此分享链接已过期</div>
  31. <el-form
  32. class="extraction-code-form"
  33. v-if="shareStep === 2"
  34. ref="codeForm"
  35. :model="dialogShareFile.codeForm"
  36. :rules="dialogShareFile.codeFormRules"
  37. label-width="80px"
  38. >
  39. <el-form-item label="提取码" prop="extractionCode">
  40. <el-input v-model="dialogShareFile.codeForm.extractionCode"></el-input>
  41. </el-form-item>
  42. </el-form>
  43. <span slot="footer" class="dialog-footer">
  44. <el-button v-if="shareStep === 1" @click="handleCloseBtnClick()">关 闭</el-button>
  45. <el-button v-else type="primary" @click="handleSubmitBtnClick('codeForm')">提 交</el-button>
  46. </span>
  47. </el-dialog>
  48. <!-- 保存到网盘 路径选择对话框 -->
  49. <MoveFileDialog
  50. :dialogData="dialogSelectPath"
  51. @setSelectFilePath="setSelectFilePath"
  52. @confirmDialog="confirmSelectPathDialog"
  53. @setDialogData="setSelectPathDialogData"
  54. ></MoveFileDialog>
  55. </div>
  56. </template>
  57. <script>
  58. import BreadCrumb from '_c/BreadCrumb'
  59. import FileTable from '_c/File/FileTable'
  60. import MoveFileDialog from '_c/File/MoveFileDialog'
  61. import {
  62. checkShareLinkEndtime,
  63. checkShareLinkType,
  64. checkShareLinkCode,
  65. getShareFileList,
  66. saveShareFile
  67. } from '_r/file.js'
  68. export default {
  69. name: 'Share',
  70. components: {
  71. BreadCrumb,
  72. FileTable,
  73. MoveFileDialog
  74. },
  75. data() {
  76. return {
  77. // 文件分享对话框数据
  78. dialogShareFile: {
  79. visible: false,
  80. codeForm: {
  81. extractionCode: ''
  82. },
  83. codeFormRules: {
  84. extractionCode: [
  85. {
  86. required: true,
  87. message: '请输入提取码',
  88. trigger: 'blur'
  89. }
  90. ]
  91. }
  92. },
  93. shareStep: 0,
  94. fileList: [],
  95. loading: false,
  96. // 保存到网盘对话框数据
  97. dialogSelectPath: {
  98. visible: false // 是否可见
  99. },
  100. selectFilePath: '', // 保存到网盘的目标路径
  101. selectionFile: [] // 表格勾选的文件列表
  102. }
  103. },
  104. computed: {
  105. shareBatchNum() {
  106. return this.$route.params.shareBatchNum
  107. },
  108. filePath() {
  109. return this.$route.query.filePath
  110. },
  111. shareFilePath() {
  112. return this.$route.query.filePath
  113. }
  114. },
  115. watch: {
  116. filePath() {
  117. this.getShareList()
  118. }
  119. },
  120. created() {
  121. if (!this.filePath) {
  122. this.$router.replace({
  123. query: {
  124. filePath: '/'
  125. }
  126. })
  127. }
  128. },
  129. mounted() {
  130. this.checkEndTime()
  131. },
  132. methods: {
  133. /**
  134. * 表格勾选框事件 | 保存被勾选的文件
  135. * @param {object[]} selection 被勾选的文件数组
  136. */
  137. setSelectionFile(selection) {
  138. this.selectionFile = selection
  139. },
  140. /**
  141. * 校验分享链接过期时间
  142. */
  143. checkEndTime() {
  144. checkShareLinkEndtime({
  145. shareBatchNum: this.shareBatchNum
  146. }).then((res) => {
  147. if (res.success) {
  148. if (this.getCookies(`share_${this.shareBatchNum}`) === 'true') {
  149. this.checkShareComplete()
  150. } else {
  151. this.dialogShareFile.visible = true
  152. this.checkShareType()
  153. }
  154. } else {
  155. this.dialogShareFile.visible = true
  156. this.shareStep = 1 // 链接已过期
  157. }
  158. })
  159. },
  160. /**
  161. * 校验分享类型
  162. * @description 校验分享链接是公共还是私密
  163. */
  164. checkShareType() {
  165. checkShareLinkType({
  166. shareBatchNum: this.shareBatchNum
  167. }).then((res) => {
  168. if (res.success) {
  169. // 0 公共 1 私密
  170. if (res.data.shareType === 0) {
  171. this.shareStep = 3 // 不是私密链接,直接展示文件列表
  172. this.getShareList()
  173. this.dialogShareFile.visible = false
  174. }
  175. if (res.data.shareType === 1) {
  176. this.shareStep = 2 // 是私密链接时,让用户输入提取码
  177. }
  178. } else {
  179. this.$message.error(res.message)
  180. }
  181. })
  182. },
  183. /**
  184. * 分享文件验证对话框 取消按钮
  185. */
  186. handleCloseBtnClick() {
  187. this.dialogShareFile.visible = false
  188. this.$router.push({ name: 'File', query: { fileType: 0, filePath: '/' } })
  189. },
  190. /**
  191. * 提交按钮点击事件
  192. */
  193. handleSubmitBtnClick(formName) {
  194. this.$refs[formName].validate((valid) => {
  195. if (valid) {
  196. checkShareLinkCode({
  197. extractionCode: this.dialogShareFile.codeForm.extractionCode,
  198. shareBatchNum: this.shareBatchNum
  199. }).then((res) => {
  200. if (res.success) {
  201. this.setCookies(`share_${this.shareBatchNum}`, true)
  202. this.$refs[formName].resetFields() // 清空表单
  203. this.checkShareComplete()
  204. } else {
  205. this.$message.error(res.message)
  206. }
  207. })
  208. } else {
  209. return false
  210. }
  211. })
  212. },
  213. /**
  214. * 校验全部通过
  215. */
  216. checkShareComplete() {
  217. this.shareStep = 3 // 展示文件列表
  218. this.dialogShareFile.visible = false
  219. this.getShareList()
  220. },
  221. /**
  222. * 获取分享文件列表
  223. */
  224. getShareList() {
  225. this.loading = true
  226. getShareFileList({
  227. shareFilePath: this.shareFilePath,
  228. shareBatchNum: this.shareBatchNum
  229. }).then((res) => {
  230. if (res.success) {
  231. this.fileList = res.data
  232. this.loading = false
  233. } else {
  234. this.$message.error(res.message)
  235. }
  236. })
  237. },
  238. /**
  239. * 保存到网盘按钮点击事件
  240. */
  241. handleSaveBtnClick() {
  242. if (this.selectionFile.length) {
  243. this.dialogSelectPath.visible = true
  244. } else {
  245. this.$message.warning('请先勾选要保存的文件')
  246. }
  247. },
  248. /**
  249. * 移动文件模态框 | 设置移动后的文件路径
  250. * @param {string} selectFilePath 目标文件夹路径
  251. */
  252. setSelectFilePath(selectFilePath) {
  253. this.selectFilePath = selectFilePath
  254. },
  255. /**
  256. * 移动文件模态框 | 确定按钮事件
  257. */
  258. confirmSelectPathDialog() {
  259. saveShareFile({
  260. filePath: this.selectFilePath,
  261. files: JSON.stringify(
  262. this.selectionFile.map((item) => {
  263. return {
  264. userFileId: item.userFileId
  265. }
  266. })
  267. )
  268. }).then((res) => {
  269. if (res.success) {
  270. this.$message.success('保存成功')
  271. this.dialogSelectPath.visible = false
  272. this.$refs.fileTableInstance.clearSelectedTable() // 清空表格已选项
  273. } else {
  274. this.$message.error(res.message)
  275. }
  276. })
  277. },
  278. /**
  279. * 设置移动文件模态框相关数据
  280. * @param {boolean} isBatchMove 是否批量移动,为 null时是确认移动,值由之前的值而定,在此业务中此致无用
  281. * @param {boolean} visible 移动文件对话框状态
  282. */
  283. setSelectPathDialogData(isBatchMove, visible) {
  284. this.dialogSelectPath.visible = visible
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="stylus" scoped>
  290. .share-wrapper {
  291. .share-file-wrapper {
  292. width: 100%;
  293. .operation-wrapper {
  294. display: flex;
  295. justify-content: space-between;
  296. padding: 8px 0;
  297. }
  298. }
  299. }
  300. </style>