group.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div class="group" v-loading="loading">
  3. <div class="group_head" v-if="user.role != 2">
  4. <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="addProject">添加新项目</el-button>
  5. </div>
  6. <div class="group_item">
  7. <div class="nodata" v-if="group.length == 0"><el-empty description="暂无项目"></el-empty></div>
  8. <div class="box" v-for="item in group" :key="item.id">
  9. <div class="main">
  10. <div class="menu">
  11. <i class="el-icon-share" @click="share(item.id)"></i>
  12. <i class="el-icon-edit" @click="rename(item.id)" v-if="item.creater_id == user.id || user.role == 0"></i>
  13. <i class="el-icon-delete" @click="del(item.id)" v-if="item.creater_id == user.id || user.role == 0"></i>
  14. </div>
  15. <div class="cover" @click="goProject(item.id)">
  16. <img class="project_cover" :src="global.host + item.cover" alt="">
  17. </div>
  18. </div>
  19. <div class="title">
  20. <p>{{item.group_name}}</p>
  21. <p>{{item.user_name}} · {{item.create_time}}</p>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import timer from '../tools/timer';
  29. import global from '@/tools/global';
  30. export default {
  31. name: 'group',
  32. data (){
  33. return {
  34. user: {},
  35. group: [],
  36. loading: true,
  37. global
  38. }
  39. },
  40. created (){
  41. this.user = JSON.parse(localStorage.getItem('designer_user'));
  42. // 没有参与项目
  43. if(this.user.projects.substring(1).length == 0){
  44. this.group = [];
  45. this.loading = false;
  46. return;
  47. }
  48. this.getgroup();
  49. },
  50. methods: {
  51. // 获取项目组列表
  52. getgroup (){
  53. // 根据id列表获取项目信息
  54. this.user.projects = this.user.projects.substring(1);
  55. this.$ajax.get('/group/list/?ids=' + this.user.projects).then(r => {
  56. this.group = r.map(item => {
  57. item.create_time = timer.time('y-m-d', item.create_time * 1000);
  58. return item;
  59. });
  60. // 处理封面展示方式,横图 = row,竖图 = col
  61. this.$nextTick(() => {
  62. let imgs = document.querySelectorAll('.project_cover');
  63. imgs.forEach(item => {
  64. let img = new Image();
  65. img.onload = () => {
  66. if(img.width > img.height){
  67. item.classList.add('row');
  68. }else{
  69. item.classList.add('col');
  70. }
  71. }
  72. img.src = item.src;
  73. })
  74. this.loading = false;
  75. })
  76. })
  77. },
  78. // 分享项目名
  79. share (id){
  80. this.group.map(item => {
  81. if(item.id == id){
  82. this.$copy(id, item.title);
  83. }
  84. })
  85. },
  86. // 重命名
  87. rename (id){
  88. let that = this;
  89. that.$prompt('请输入新的项目名称', '重命名', {
  90. inputPattern: /\S/,
  91. inputErrorMessage: '请输入项目名',
  92. closeOnPressEscape: false,
  93. closeOnClickModal: false,
  94. beforeClose (action, instance, done){
  95. if(action == 'confirm'){
  96. that.$ajax.post('/group/rename', {
  97. id,
  98. name: instance.inputValue
  99. }).then(r => {
  100. that.$message.success('修改成功');
  101. that.group.map(item => {
  102. if(item.id == id){
  103. item.group_name = instance.inputValue;
  104. }
  105. })
  106. done();
  107. })
  108. }else{
  109. done();
  110. }
  111. }
  112. }).catch(() => {});
  113. },
  114. // 删除项目
  115. del (id){
  116. let that = this;
  117. this.$confirm('此操作将永久删除该项目, 是否继续?', '提示', {
  118. type: 'warning',
  119. closeOnPressEscape: false,
  120. closeOnClickModal: false,
  121. beforeClose (action, instance, done){
  122. if(action == 'confirm'){
  123. let index = 0;
  124. that.group.map((item, i) => {
  125. if(item.id == id){
  126. index = i;
  127. }
  128. })
  129. that.$ajax.get('/group/del/?id=' + id).then(r => {
  130. that.group.splice(index, 1);
  131. that.$message.success('删除成功');
  132. done();
  133. })
  134. }else{
  135. done();
  136. }
  137. }
  138. }).catch(() => {});
  139. },
  140. // 查看项目
  141. goProject (id){
  142. this.$router.push({
  143. path: '/list',
  144. query: { id }
  145. })
  146. },
  147. // 添加新项目
  148. addProject (){
  149. let that = this;
  150. that.$prompt('请输入项目名称', '添加新项目', {
  151. inputPattern: /\S/,
  152. inputErrorMessage: '请输入项目名',
  153. closeOnPressEscape: false,
  154. closeOnClickModal: false,
  155. beforeClose (action, instance, done){
  156. if(action == 'confirm'){
  157. that.$ajax.post('/group/add', {
  158. name: instance.inputValue,
  159. createrId: JSON.parse(localStorage.getItem('designer_user')).id
  160. }).then(r => {
  161. done();
  162. that.setGroup(r);
  163. that.$message.success('添加成功');
  164. })
  165. }else{
  166. done();
  167. }
  168. }
  169. }).catch(() => {});
  170. },
  171. // 更新项目id
  172. setGroup (r){
  173. this.user.projects = r;
  174. localStorage.setItem('designer_user', JSON.stringify(this.user));
  175. this.getgroup();
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="less" scoped>
  181. @import url('../tools/common.less');
  182. .group{
  183. width: calc(100% - 60px);
  184. height: 100%;
  185. padding: 0 30px;
  186. display: flex;
  187. justify-content: flex-start;
  188. align-content: flex-start;
  189. flex-wrap: wrap;
  190. overflow-x: hidden;
  191. overflow-y: auto;
  192. .group_head{
  193. width: calc(100% - 20px);
  194. height: 40px;
  195. padding: 20px 10px;
  196. display: flex;
  197. justify-content: flex-start;
  198. align-items: center;
  199. }
  200. .group_item{
  201. width: 100%;
  202. height: calc(100% - 80px);
  203. display: flex;
  204. justify-content: flex-start;
  205. align-content: flex-start;
  206. flex-wrap: wrap;
  207. overflow-x: hidden;
  208. overflow-y: auto;
  209. .nodata{
  210. width: 100%;
  211. height: 70%;
  212. display: flex;
  213. justify-content: center;
  214. align-items: center;
  215. }
  216. .box{
  217. width: 240px;
  218. height: 300px;
  219. background: #ffffff;
  220. border-radius: 5px;
  221. margin: 10px;
  222. box-shadow: 0px 3px 7px 0px rgba(0,0,0,0.0500);
  223. .main{
  224. width: 220px;
  225. height: 220px;
  226. background: #F5F5F7;
  227. border-radius: 5px;
  228. margin: 10px;
  229. transition: all 0.3s;
  230. .menu{
  231. width: 220px;
  232. height: 30px;
  233. line-height: 30px;
  234. display: flex;
  235. justify-content: flex-end;
  236. align-items: center;
  237. i{
  238. display: block;
  239. font-size: 14px;
  240. margin-right: 15px;
  241. color: #888888;
  242. cursor: pointer;
  243. }
  244. i:hover{
  245. color: @color;
  246. }
  247. i.designer-gengduo{
  248. font-size: 20px;
  249. }
  250. }
  251. .cover{
  252. width: 200px;
  253. height: 170px;
  254. padding: 10px;
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. cursor: pointer;
  259. overflow: hidden;
  260. img.row{
  261. width: 100%;
  262. border-radius: 10px;
  263. }
  264. img.col{
  265. height: 100%;
  266. border-radius: 10px;
  267. }
  268. }
  269. }
  270. .title{
  271. width: 240px;
  272. height: 60px;
  273. text-align: center;
  274. p:last-child{
  275. margin-top: 5px;
  276. font-size: 12px;
  277. color: #888888;
  278. }
  279. }
  280. &:hover{
  281. .main{
  282. background: #F8F5F2;
  283. }
  284. }
  285. }
  286. }
  287. .group_item::-webkit-scrollbar{
  288. display: none;
  289. }
  290. }
  291. </style>