authorize.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class='flex flex-justify-between flex-col full-width '>
  3. <div v-if='folderName' class='bold'>当前授权文件夹{{folderName}}</div>
  4. <div class='flex flex-justify-start flex-align-center full-width' v-if='authorType'>
  5. <span class='bold'>授权模式:</span>
  6. <el-radio-group v-model='grantType'>
  7. <el-radio :label="1">项目全托管</el-radio>
  8. <el-radio :label="0">按文件授权</el-radio>
  9. </el-radio-group>
  10. </div>
  11. <el-tabs v-if='grantType === 0' class='mt-20' type='border-card' v-model='initType'>
  12. <el-tab-pane label='授权子文件夹'>
  13. <div class='flex full-width full-height flex-justify-around border-bottom padding-bottom bold '>
  14. <span class='text-center'>文件夹名称</span>
  15. <span class='text-center'>权限设置</span>
  16. </div>
  17. <div class='border-bottom padding-right padding-left mt-10' style='height: 500px'>
  18. <div class='flex flex-align-center mb-10 flex-justify-between border-bottom'>
  19. <div class='bold'>文件夹相关权限</div>
  20. <el-radio-group v-model="check" @change='allChange($event,1)'>
  21. <el-radio label="1" size="large">可见</el-radio>
  22. <el-radio label="2" size="large">可编辑</el-radio>
  23. <el-radio label="3" size="large">不可操作</el-radio>
  24. </el-radio-group>
  25. </div>
  26. <div style='overflow-y: scroll; height: 450px' v-loading='loading'>
  27. <div v-for='(item,index) in folderList' :key='item.id'>
  28. <item1 :check='item.check' :data='item' :index='index' @change='change($event,1)'/>
  29. </div>
  30. </div>
  31. </div>
  32. </el-tab-pane>
  33. <el-tab-pane label='授权子文件'>
  34. <div class='flex full-width full-height flex-justify-around border-bottom padding-bottom bold '>
  35. <span class='flex-child-average text-center'>文件名称</span>
  36. <span class='flex-child-average text-center'>权限设置</span>
  37. </div>
  38. <div class='border-bottom padding-right padding-left mt-10' style='height: 500px'>
  39. <div class='flex flex-align-center mb-10 flex-justify-between border-bottom'>
  40. <div class='bold'>文件相关权限</div>
  41. <el-radio-group v-model="check" @change='allChange($event,2)'>
  42. <el-radio label="3" size="large">不可查看</el-radio>
  43. <el-radio label="1" size="large">可见</el-radio>
  44. <el-radio label="2" size="large">可编辑</el-radio>
  45. </el-radio-group>
  46. </div>
  47. <div style='overflow-y: scroll; height: 450px'>
  48. <div v-for='(item,index) in fileList' :key='item.id'>
  49. <item1 :check='item.check' :data='item' :index='index' @change='change($event,2)'/>
  50. </div>
  51. </div>
  52. </div>
  53. </el-tab-pane>
  54. </el-tabs>
  55. <div>
  56. <div class='full-width flex flex-align-center mt-10'>
  57. <span class='font-14 bold'>授权时长</span>
  58. <el-date-picker
  59. v-model="authorizeDate"
  60. class='ml-20'
  61. end-placeholder="截止日期"
  62. range-separator="至"
  63. start-placeholder="开始日期"
  64. type="daterange"
  65. value-format='YYYY-MM-DD'
  66. format='YYYY-MM-DD'
  67. />
  68. </div>
  69. <div class='full-width flex flex-align-center mt-10'>
  70. <span class='font-14 bold'>授权方式</span>
  71. <el-radio-group v-model="access" class='ml-20'>
  72. <el-radio :label="1">应用到所以文件夹及文件</el-radio>
  73. <el-radio :label="2">应用到子文件夹</el-radio>
  74. <el-radio :label="3">应用到子文件夹的文件</el-radio>
  75. </el-radio-group>
  76. </div>
  77. <div class='full-width flex flex-align-center mt-10'>
  78. <span class='font-14 bold'>生成授权连接</span>
  79. <el-button circle class='ml-20' icon="Picture" type="danger" @click='initCode(2)'/>
  80. <!-- <el-button circle icon="Paperclip" type="danger"/>-->
  81. </div>
  82. <div class='full-width mt-20 border-top padding-top flex flex-justify-end'>
  83. <el-button @click='close'>取消</el-button>
  84. <el-button type='primary' @click='close'>关闭</el-button>
  85. </div>
  86. </div>
  87. <el-dialog v-model='qrCodeShow' top='20%' width='400px'>
  88. <div class='flex flex-col flex-center' style='height: 400rpx;width: 400rpx'>
  89. <vue-qr :currentLevel='3' :logoCornerRadius='4' :logoScale='0.25' :text='qrCodeText'
  90. size='340'/>
  91. <span>右键复制二维码,通过微信进行分享</span>
  92. </div>
  93. </el-dialog>
  94. </div>
  95. </template>
  96. <script>
  97. import item1 from '@/views/home/component/item1.vue'
  98. import VueQr from 'vue-qr/src/packages/vue-qr.vue'
  99. export default {
  100. name: 'authorize',
  101. components: { item1, VueQr },
  102. props: {
  103. list: {
  104. type: Array,
  105. default: null
  106. },
  107. folderId: {
  108. type: String,
  109. default: ''
  110. },
  111. projectId: {
  112. type: String,
  113. default: ''
  114. },
  115. extra: {
  116. type: Object,
  117. default: null
  118. },
  119. // 是否显示授权模式
  120. authorType: {
  121. type: Boolean,
  122. default: true
  123. },
  124. // 当前授权文件夹
  125. folderName: {
  126. type: String,
  127. default: ''
  128. }
  129. },
  130. watch: {
  131. list: {
  132. handler (val) {
  133. val = val.map(sub => {
  134. sub.check = this.check
  135. return sub
  136. })
  137. this.folderList = val.filter(sub => sub.type !== 1)
  138. this.fileList = val.filter(sub => sub.type === 1)
  139. },
  140. immediate: true
  141. }
  142. },
  143. data () {
  144. return {
  145. loading: false,
  146. check: '2',
  147. authorizeDate: [],
  148. access: 1,
  149. fileData: null,
  150. qrCodeShow: false,
  151. fileList: [],
  152. folderList: [],
  153. qrCodeText: '',
  154. defaultDate: [],
  155. // 0 部分授权,1 全托管授权
  156. grantType: 0,
  157. initType: '0'
  158. }
  159. },
  160. methods: {
  161. close () {
  162. this.$emit('close')
  163. },
  164. initCode () {
  165. this.loading = true
  166. let list = this.folderList
  167. if (this.initType === '1') {
  168. list = this.fileList
  169. }
  170. console.log(list)
  171. if (this.authorizeDate.length === 0) {
  172. this.$message.error('请设置授权时间')
  173. return
  174. }
  175. this.startTime = this.authorizeDate[0]
  176. this.endTime = this.authorizeDate[1]
  177. const fileTmps = list.map(sub => {
  178. const item = { fileId: sub.id, startTime: this.startTime, endTime: this.endTime, status: sub.check }
  179. return item
  180. })
  181. const folder = [{
  182. folderId: this.folderId,
  183. startTime: this.startTime,
  184. endTime: this.endTime,
  185. status: this.check
  186. }]
  187. const folderTmp = list.map(sub => {
  188. const item = {
  189. folderId: sub.hasOwnProperty('fileFolderId') ? sub.fileFolderId : sub.id,
  190. startTime: this.startTime,
  191. endTime: this.endTime,
  192. status: sub.check,
  193. folderName: sub.title
  194. }
  195. return item
  196. })
  197. const query = []
  198. for (const k in this.extra) {
  199. query.push(k + '=' + this.extra[k])
  200. }
  201. const data = {
  202. files: this.initType === '0' ? [] : fileTmps,
  203. folders: this.folderId.length === 0 ? folderTmp : folder.concat(folderTmp),
  204. projectId: this.projectId,
  205. grantType: this.grantType,
  206. startTime: this.startTime,
  207. endTime: this.endTime
  208. }
  209. this.$api.project.initCode(Object.assign(data, this.extra)).then(res => {
  210. this.loading = false
  211. if (res.code === 200) {
  212. this.qrCodeText = 'https://dev.wutongresearch.club/apply?id=' + res.data + (query.length > 0 ? '&' + query.join('&') : '')
  213. this.qrCodeShow = true
  214. } else {
  215. this.$message.error(res.msg)
  216. }
  217. })
  218. },
  219. allChange (res, type) {
  220. console.log(res)
  221. if (type === 1) {
  222. this.folderList.forEach(sub => {
  223. sub.check = res
  224. return sub
  225. })
  226. console.log(this.folderList)
  227. } else {
  228. this.fileList.forEach(sub => {
  229. sub.check = res
  230. return sub
  231. })
  232. }
  233. },
  234. change (res, type) {
  235. if (type === 1) {
  236. this.folderList[res.index] = res
  237. let seeCount = 0
  238. let editCount = 0
  239. let notCount = 0
  240. this.folderList.forEach(sub => {
  241. if (sub.check === '1') {
  242. seeCount = seeCount + 1
  243. } else if (sub.check === '2') {
  244. editCount = editCount + 1
  245. } else {
  246. notCount = notCount + 1
  247. }
  248. })
  249. if (editCount >= seeCount || editCount > 0) {
  250. this.check = '2'
  251. } else if (seeCount > 0) {
  252. this.check = '1'
  253. } else {
  254. this.check = '3'
  255. }
  256. } else {
  257. this.fileList[res.index] = res
  258. let seeCount = 0
  259. let editCount = 0
  260. let notCount = 0
  261. this.fileList.forEach(sub => {
  262. if (sub.check === '1') {
  263. seeCount = seeCount + 1
  264. } else if (sub.check === '2') {
  265. editCount = editCount + 1
  266. } else {
  267. notCount = notCount + 1
  268. }
  269. })
  270. if (editCount >= seeCount || editCount > 0) {
  271. this.check = '2'
  272. } else if (seeCount > 0) {
  273. this.check = '1'
  274. } else {
  275. this.check = '3'
  276. }
  277. }
  278. }
  279. }
  280. }
  281. </script>
  282. <style scoped>
  283. </style>