select.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div class="filebox">
  3. <el-card shadow="never">
  4. <div class="left">
  5. <el-button type="primary" @click="addCate">添加分类</el-button>
  6. <el-input placeholder="请输入分类搜索" style="margin: 15px 0;"></el-input>
  7. <el-scrollbar height="320px" style="margin:0 -10px;">
  8. <div :class="['li',category=='all'?'active':'']" @click="checkCategory('all');">
  9. <i :class="['fa',category=='all'?'fa-folder-open-o':'fa-folder-o']"></i>&nbsp;&nbsp;全部
  10. </div>
  11. <div :class="['li',category=='unclassed'?'active':'']" @click="checkCategory('unclassed');">
  12. <i :class="['fa',category==''?'fa-folder-open-o':'fa-folder-o']"></i>&nbsp;&nbsp;未归类
  13. </div>
  14. <template v-for="(item,key) in catelist">
  15. <div :class="['li',category==key?'active':'']" @click="checkCategory(key);">
  16. <i :class="['fa',category==key?'fa-folder-open-o':'fa-folder-o']"></i>&nbsp;&nbsp;{{item}}
  17. <div class="fr"><span @click.stop="editCate(key,item)">编辑</span>|<span @click.stop="delCate(key,item)">删除</span></div>
  18. </div>
  19. </template>
  20. </el-scrollbar>
  21. </div>
  22. <div class="right">
  23. <el-input placeholder="请输入名称搜索" style="width: 725px;margin-left: 7px;" v-model="keywords">
  24. <template #append>
  25. <el-button type="primary" size="small" @click="refresh">搜索</el-button>
  26. </template>
  27. </el-input>
  28. <el-upload
  29. :multiple="true"
  30. accept="image/*"
  31. action="{$config.baseUrl}{$config.upload.uploadurl}"
  32. :data="{category:category,disks:'{$config.upload.disks}'}"
  33. :headers="{'x-requested-with': 'XMLHttpRequest'}"
  34. list-type="picture-card"
  35. :on-success="beforeUploadSuccess"
  36. :file-list="list">
  37. <i class="fa fa-cloud-upload"></i>
  38. <template #file="{file}">
  39. <div :class="inArray(file.fullurl)!==false?'checked':''" @click="checkImg(file)">
  40. <div class="img">
  41. <img @load="parseImg" class="upload-file-img" :data-url="file.thumburl" style="width: 100%"/>
  42. </div>
  43. <span>{{file.filename}}</span>
  44. <i class="fa fa-check"></i>
  45. </div>
  46. </template>
  47. </el-upload>
  48. <el-pagination
  49. style="position: absolute;bottom: 15px;right: 15px"
  50. @current-change="pageChange"
  51. small
  52. :page-size="17"
  53. :current-page="page"
  54. background
  55. layout="prev, pager, next"
  56. :total="total"
  57. ></el-pagination>
  58. </div>
  59. </el-card>
  60. <div class="footer">
  61. <el-button type="danger" @click="delPic">删除</el-button>
  62. <el-button type="warning" @click="setCategory">归类</el-button>
  63. <el-button type="primary" @click="confirmImg">选定</el-button>
  64. <el-button type="success" @click="refresh">刷新</el-button>
  65. </div>
  66. </div>
  67. <el-dialog
  68. v-model="editCateForm.show"
  69. destroy-on-close
  70. :lock-scroll="false"
  71. :title="editCateForm.title"
  72. width="50%"
  73. :modal="false"
  74. align-center>
  75. <el-select style="width: 100%" v-model="editCateForm.key" v-if="editCateForm.type=='set'">
  76. <el-option
  77. v-for="(item,key) in catelist"
  78. :key="key"
  79. :label="item"
  80. :value="key">
  81. </el-option>
  82. </el-select>
  83. <el-input placeholder="请输入分类名称" v-model="editCateForm.value" v-else></el-input>
  84. <template #footer>
  85. <span class="dialog-footer">
  86. <el-button type="danger" @click="editCateForm.show=false">取消</el-button>
  87. <el-button type="primary" @click="confirm">确认</el-button>
  88. </span>
  89. </template>
  90. </el-dialog>
  91. </template>
  92. <script>
  93. export default{
  94. data:{
  95. list:[],
  96. page:1,
  97. category:'all',
  98. catelist:Yunqi.data.categoryList,
  99. checked:[],
  100. keywords:'',
  101. total:0,
  102. editCateForm:{
  103. show:false,
  104. type:'add',
  105. key:'',
  106. value:''
  107. },
  108. loading:false,
  109. limit:Yunqi.data.limit,
  110. },
  111. onLoad:function (){
  112. this.getImglist();
  113. },
  114. methods: {
  115. inArray:function (url) {
  116. let r=false;
  117. for(let i=0;i<this.checked.length;i++){
  118. if(this.checked[i].fullurl==url){
  119. r=i;
  120. break;
  121. }
  122. }
  123. return r;
  124. },
  125. beforeUploadSuccess:function (res,file) {
  126. if(res.code===0){
  127. Yunqi.message.error(__(res.msg));
  128. }
  129. this.list=[];
  130. setTimeout(()=>{
  131. this.refresh();
  132. },500);
  133. },
  134. checkCategory:function (key) {
  135. this.category=key;
  136. this.refresh();
  137. },
  138. addCate:function () {
  139. this.editCateForm.type='add';
  140. this.editCateForm.title='添加分类';
  141. this.editCateForm.key='fold-'+(this.catelist.length+1);
  142. this.editCateForm.show=true;
  143. },
  144. editCate:function (key,value) {
  145. this.editCateForm.type='edit';
  146. this.editCateForm.title='编辑分类';
  147. this.editCateForm.key=key;
  148. this.editCateForm.value=value;
  149. this.editCateForm.show=true;
  150. },
  151. delCate:function (key,value) {
  152. this.editCateForm.type='del';
  153. this.editCateForm.key=key;
  154. this.editCateForm.value=value;
  155. Yunqi.confirm('确定删除分类【'+value+'】吗?').then(res=>{
  156. Yunqi.ajax.post('general/attachment/setcate',this.editCateForm).then(res=>{
  157. this.catelist=res;
  158. this.category='all';
  159. this.refresh();
  160. });
  161. });
  162. },
  163. confirm:function () {
  164. if(this.editCateForm.type=='set'){
  165. let ids=[];
  166. this.checked.forEach(item=>{
  167. ids.push(item.id);
  168. });
  169. if (ids.length==0){
  170. Yunqi.message.error('请选择要删除的图片!');
  171. return;
  172. }
  173. Yunqi.ajax.post('general/attachment/classify', {
  174. ids:ids.join(','),
  175. category:this.editCateForm.key
  176. }).then(res=>{
  177. this.editCateForm.show=false;
  178. this.category=this.editCateForm.key;
  179. this.checked=[];
  180. this.refresh();
  181. });
  182. }else{
  183. Yunqi.ajax.post('general/attachment/setcate',this.editCateForm).then(res=>{
  184. this.catelist=res;
  185. this.editCateForm.show=false;
  186. this.category=this.editCateForm.key;
  187. this.refresh();
  188. });
  189. }
  190. },
  191. delPic:function () {
  192. let ids=[];
  193. this.checked.forEach(item=>{
  194. ids.push(item.id);
  195. });
  196. if (ids.length==0){
  197. Yunqi.message.error('请选择要删除的图片!');
  198. return;
  199. }
  200. Yunqi.confirm('确定删除这'+ids.length+'张图片吗?').then(res=>{
  201. Yunqi.ajax.post('general/attachment/del',{ids:ids.join(',')}).then(res=>{
  202. this.getImglist();
  203. this.checked=[];
  204. });
  205. });
  206. },
  207. setCategory:function () {
  208. if (this.checked.length===0){
  209. Yunqi.message.error('请选择要归类的图片!');
  210. return;
  211. }
  212. this.editCateForm.type='set';
  213. this.editCateForm.title='图片归类';
  214. this.editCateForm.show=true;
  215. },
  216. refresh:function () {
  217. this.page=1;
  218. this.getImglist();
  219. },
  220. pageChange:function (page) {
  221. this.page=page;
  222. this.getImglist();
  223. },
  224. getImglist:function () {
  225. this.loading=true;
  226. Yunqi.ajax.get('general/attachment/select',{
  227. page:this.page,
  228. category:this.category,
  229. keywords:this.keywords,
  230. }).then(res=>{
  231. this.total=res.total;
  232. this.list=res.rows;
  233. this.loading=false;
  234. Vue.nextTick(()=>{
  235. this.parseImg();
  236. });
  237. });
  238. },
  239. parseImg:function(){
  240. if(this.loading){
  241. return;
  242. }
  243. let imgs=document.querySelectorAll('img[class="upload-file-img"]');
  244. if(imgs.length==0){
  245. return;
  246. }
  247. let url=imgs[0].dataset.url;
  248. imgs[0].setAttribute('src',url);
  249. imgs[0].removeAttribute('class');
  250. },
  251. confirmImg:function () {
  252. let imgs=[];
  253. this.checked.forEach(res=>{
  254. imgs.push(res.fullurl);
  255. });
  256. Yunqi.api.closelayer(Yunqi.app.window.id,imgs);
  257. },
  258. checkImg:function (file) {
  259. let xi=this.inArray(file.fullurl);
  260. if(xi!==false){
  261. this.checked.splice(xi,1);
  262. }else{
  263. if(this.checked.length==this.limit){
  264. this.checked.shift();
  265. }
  266. this.checked.push(file);
  267. }
  268. }
  269. }
  270. }
  271. </script>
  272. <style>
  273. .filebox{
  274. padding: 10px;
  275. }
  276. .el-card__body{
  277. display: flex;
  278. flex-direction: row;
  279. justify-content: space-between;
  280. padding:0;
  281. }
  282. .el-card__body>.left{
  283. width: 20%;
  284. height: 470px;
  285. padding:10px;
  286. }
  287. .el-card__body>.left .li{
  288. height: 40px;
  289. line-height: 40px;
  290. cursor: pointer;
  291. padding: 0 10px;
  292. }
  293. .el-card__body>.left .li:hover{
  294. background-color: var(--el-color-primary-light-8);
  295. }
  296. .el-card__body>.left .li.active{
  297. background-color: var(--el-color-primary-light-8);
  298. }
  299. .el-card__body>.left .li .fr{
  300. float:right;
  301. display: flex;
  302. width: 60px;
  303. justify-content: space-between;
  304. font-size:12px;
  305. color: var(--el-color-primary);
  306. }
  307. .el-card__body>.left .li .fr span:hover{
  308. color: var(--el-color-primary-light-3);
  309. }
  310. .el-card__body>.right{
  311. width: 80%;
  312. border-left:1px solid var(--el-border-color-light);
  313. padding:12px;
  314. position: relative;
  315. }
  316. .el-upload{
  317. width: 110px;
  318. height: 110px;
  319. margin: 15px 13px 0 0;
  320. border-radius: 5px;
  321. position:relative;
  322. border: 1px dashed #ccc;
  323. }
  324. .el-upload-list .is-ready,.el-upload-list .is-uploading{
  325. display: none;
  326. }
  327. .el-upload-list .el-upload-list__item{
  328. width: 110px;
  329. height: 110px;
  330. margin: 15px 13px 0 0;
  331. border-radius: 5px;
  332. position:relative;
  333. border: 1px dashed #ccc;
  334. }
  335. .el-upload-list .el-upload-list__item .img{
  336. width: 90px;
  337. height: 90px;
  338. position: absolute;
  339. left:10px;
  340. top:10px;
  341. overflow: hidden;
  342. cursor: pointer;
  343. background-repeat: no-repeat;
  344. background-size: contain;
  345. background-position: center;
  346. }
  347. .el-upload-list .el-upload-list__item span{
  348. display: inline-block;
  349. overflow: hidden;
  350. text-overflow: ellipsis;
  351. white-space: nowrap;
  352. width: 98%;
  353. font-size: 12px;
  354. text-align: center;
  355. color: #000;
  356. position:absolute;
  357. border-radius:3px;
  358. bottom:1px;
  359. left:1%;
  360. background-color: rgb(110,110,110,0.5);
  361. }
  362. .el-upload-list .el-upload-list__item .checked span{
  363. background-color: var(--el-color-primary);
  364. color:#fff;
  365. }
  366. .el-upload-list .fa-check{
  367. display: none;
  368. }
  369. .el-upload-list .checked .fa-check{
  370. color:var(--el-color-primary);
  371. position: absolute;
  372. right:10px;
  373. top:10px;
  374. font-size:24px;
  375. display:inline;
  376. }
  377. .footer{
  378. display: flex;
  379. justify-content: flex-end;
  380. align-items: center;
  381. }
  382. .footer .el-button{
  383. position: relative;
  384. top:7px;
  385. }
  386. </style>