authorize.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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-button circle class='ml-20' icon="Picture" type="danger" @click='initCode(2)'/>
  72. <!-- <el-button circle icon="Paperclip" type="danger"/>-->
  73. </div>
  74. <div class='full-width mt-20 border-top padding-top flex flex-justify-end'>
  75. <el-button @click='close'>取消</el-button>
  76. <el-button type='primary' @click='close'>关闭</el-button>
  77. </div>
  78. </div>
  79. <el-dialog v-model='qrCodeShow' top='20%' width='400px'>
  80. <div class='flex flex-col flex-center' style='height: 400rpx;width: 400rpx'>
  81. <vue-qr :currentLevel='3' :logoCornerRadius='4' :logoScale='0.25' :text='qrCodeText'
  82. size='340'/>
  83. <span>右键复制二维码,通过微信进行分享</span>
  84. {{qrCodeText}}
  85. </div>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. import item1 from '@/views/home/component/item1.vue'
  91. import VueQr from 'vue-qr/src/packages/vue-qr.vue'
  92. export default {
  93. name: 'authorize',
  94. components: { item1, VueQr },
  95. props: {
  96. list: {
  97. type: Array,
  98. default: null
  99. },
  100. folderId: {
  101. type: String,
  102. default: ''
  103. },
  104. projectId: {
  105. type: String,
  106. default: ''
  107. },
  108. extra: {
  109. type: Object,
  110. default: null
  111. },
  112. // 是否显示授权模式
  113. authorType: {
  114. type: Boolean,
  115. default: true
  116. },
  117. // 当前授权文件夹
  118. folderName: {
  119. type: String,
  120. default: ''
  121. }
  122. },
  123. watch: {
  124. list: {
  125. handler (val) {
  126. val = val.map(sub => {
  127. sub.check = this.check
  128. return sub
  129. })
  130. this.folderList = val.filter(sub => sub.type !== 1)
  131. this.fileList = val.filter(sub => sub.type === 1)
  132. },
  133. immediate: true
  134. }
  135. },
  136. data () {
  137. return {
  138. loading: false,
  139. check: '2',
  140. authorizeDate: [],
  141. access: 1,
  142. fileData: null,
  143. qrCodeShow: false,
  144. fileList: [],
  145. folderList: [],
  146. qrCodeText: '',
  147. defaultDate: [],
  148. // 0 部分授权,1 全托管授权
  149. grantType: 0,
  150. initType: '0'
  151. }
  152. },
  153. methods: {
  154. close () {
  155. this.$emit('close')
  156. },
  157. initCode () {
  158. this.loading = true
  159. let list = this.folderList
  160. if (this.initType === '1') {
  161. list = this.fileList
  162. }
  163. console.log(list)
  164. if (this.authorizeDate.length === 0) {
  165. this.$message.error('请设置授权时间')
  166. return
  167. }
  168. this.startTime = this.authorizeDate[0]
  169. this.endTime = this.authorizeDate[1]
  170. const fileTmps = list.map(sub => {
  171. const item = { fileId: sub.id, startTime: this.startTime, endTime: this.endTime, status: sub.check }
  172. return item
  173. })
  174. const folder = [{
  175. folderId: this.folderId,
  176. startTime: this.startTime,
  177. endTime: this.endTime,
  178. status: this.check
  179. }]
  180. const folderTmp = list.map(sub => {
  181. const item = {
  182. folderId: sub.hasOwnProperty('fileFolderId') ? sub.fileFolderId : sub.id,
  183. startTime: this.startTime,
  184. endTime: this.endTime,
  185. status: sub.check,
  186. folderName: sub.title
  187. }
  188. return item
  189. })
  190. const query = []
  191. for (const k in this.extra) {
  192. query.push(k + '=' + this.extra[k])
  193. }
  194. const data = {
  195. files: this.initType === '0' ? [] : fileTmps,
  196. folders: this.folderId.length === 0 ? folderTmp : folder.concat(folderTmp),
  197. projectId: this.projectId,
  198. grantType: this.grantType,
  199. startTime: this.startTime,
  200. endTime: this.endTime
  201. }
  202. this.$api.project.initCode(Object.assign(data, this.extra)).then(res => {
  203. this.loading = false
  204. if (res.code === 200) {
  205. this.qrCodeText = 'https://dev.wutongresearch.club/apply?id=' + res.data + (query.length > 0 ? '&' + query.join('&') : '')
  206. this.qrCodeShow = true
  207. } else {
  208. this.$message.error(res.msg)
  209. }
  210. })
  211. },
  212. allChange (res, type) {
  213. console.log(res)
  214. if (type === 1) {
  215. this.folderList.forEach(sub => {
  216. sub.check = res
  217. return sub
  218. })
  219. console.log(this.folderList)
  220. } else {
  221. this.fileList.forEach(sub => {
  222. sub.check = res
  223. return sub
  224. })
  225. }
  226. },
  227. change (res, type) {
  228. if (type === 1) {
  229. this.folderList[res.index] = res
  230. let seeCount = 0
  231. let editCount = 0
  232. let notCount = 0
  233. this.folderList.forEach(sub => {
  234. if (sub.check === '1') {
  235. seeCount = seeCount + 1
  236. } else if (sub.check === '2') {
  237. editCount = editCount + 1
  238. } else {
  239. notCount = notCount + 1
  240. }
  241. })
  242. if (editCount >= seeCount || editCount > 0) {
  243. this.check = '2'
  244. } else if (seeCount > 0) {
  245. this.check = '1'
  246. } else {
  247. this.check = '3'
  248. }
  249. } else {
  250. this.fileList[res.index] = res
  251. let seeCount = 0
  252. let editCount = 0
  253. let notCount = 0
  254. this.fileList.forEach(sub => {
  255. if (sub.check === '1') {
  256. seeCount = seeCount + 1
  257. } else if (sub.check === '2') {
  258. editCount = editCount + 1
  259. } else {
  260. notCount = notCount + 1
  261. }
  262. })
  263. if (editCount >= seeCount || editCount > 0) {
  264. this.check = '2'
  265. } else if (seeCount > 0) {
  266. this.check = '1'
  267. } else {
  268. this.check = '3'
  269. }
  270. }
  271. }
  272. }
  273. }
  274. </script>
  275. <style scoped>
  276. </style>