list.vue 12 KB

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