images.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <!DOCTYPE html>
  2. <!--suppress JSAnnotator -->
  3. <html lang="zh-CN">
  4. <head>
  5. <link href="{__PLUG_PATH}layui/css/layui.css" rel="stylesheet">
  6. <script src="{__PLUG_PATH}jquery-1.10.2.min.js"></script>
  7. <script src="{__PLUG_PATH}layui/layui.all.js"></script>
  8. <script src="{__PLUG_PATH}vue/dist/vue.min.js"></script>
  9. </head>
  10. <style>
  11. body{-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;}
  12. .layui-fluid{margin:0;padding: 0;}
  13. .layadmin-homepage-shadow{box-shadow: 0 1px 1px rgba(0,0,0,.05);background-color: #fff;border-radius: 0;border: 1px solid #e7ecf3;}
  14. .layui-tree-txt{cursor: pointer;}
  15. .clearfix:after{content:"";display:block;visibility:hidden;clear:both;height:0;}
  16. .image-box{padding-top: 10px}
  17. .image-box .image .layui-img-box{margin: 5px;border: 2px solid #ffffff;height: 100px;line-height: 100px;text-align: center;}
  18. .image-box .image .layui-img-box.on{border: 2px solid #5FB878;}
  19. .image-box .image .layui-img-box img{width: 90%;max-height:90%;vertical-align:middle;}
  20. .page .image_page{text-align: right;}
  21. .page .layui-box{text-align: left;}
  22. .layui-tree-txt.on{color:#1E9FFF}
  23. .line1{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width: 90%;}
  24. .layadmin-homepage-panel.left ::-webkit-scrollbar{width: 3px;height: auto;background-color: #ddd;}
  25. .layadmin-homepage-panel.left ::-webkit-scrollbar-thumb {border-radius: 1px;-webkit-box-shadow: inset 0 0 6px rgba(255,255,255,.3);background-color: #333;}
  26. .layadmin-homepage-panel.left ::-webkit-scrollbar-track {-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);border-radius: 1px;background: #e5e5e5;}
  27. #app .layui-tree-btnGroup{color: #ffffff;padding: 3px 7px;position: absolute;top: -28px;left: 30px;background-color: #1E9FFF;}
  28. #app .layui-tree-btnGroup .layui-layer-TipsT{border-right-color: #1E9FFF;color: #ffffff}
  29. #app .layui-tree-iconClick{margin:0 0 0 9px;}
  30. @media screen and (min-width:1000px){
  31. .image-box .image .layui-img-box{
  32. height: 200px;
  33. line-height: 200px;
  34. }
  35. }
  36. </style>
  37. <body style="background-color: #f2f2f2">
  38. <div class="layui-fluid" id="app">
  39. <div class="layui-row">
  40. <div class="layui-col-md2 layui-col-xs2 layui-col-sm2">
  41. <div class="layadmin-homepage-panel layadmin-homepage-shadow left">
  42. <div class="layui-card text-center">
  43. <div class="layui-card-header">
  44. <div class="layui-unselect layui-form-select layui-form-selected">
  45. <div class="layui-select-title">
  46. <input type="text" name="title" v-model="searchTitle" placeholder="搜索分类" style="height: 24px;line-height:24px;padding-left:7px;font-size: 12px;display: inline;padding-right: 0;width: 100%;" autocomplete="off" class="layui-input layui-input-search" @keydown="search">
  47. <!-- <i class="layui-icon layui-icon-search" @click="search" style="cursor: pointer;margin:0 3px;"></i>-->
  48. </div>
  49. </div>
  50. </div>
  51. <div class="layui-card-body" style="padding: 0;height: 455px;overflow:auto;">
  52. <!-- <div class="layadmin-homepage-pad-ver">-->
  53. <!-- <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" style="width: 80%" @click="addCategory">添加</button>-->
  54. <!-- </div>-->
  55. <div ref="tree" class="demo-tree demo-tree-box">
  56. <div class="layui-tree layui-tree-line">
  57. <div class="layui-tree-set layui-tree-setHide">
  58. <div class="layui-tree-entry">
  59. <div class="layui-tree-main" @click="OpenTree({child:[],id:0})">
  60. <span class="layui-tree-iconClick">
  61. <i class="layui-icon">&nbsp;&nbsp;&nbsp;</i>
  62. </span>
  63. <span class="layui-tree-txt" :class="pid == 0 ? 'on' : '' ">全部图片</span>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="layui-tree-set layui-tree-setHide" :class=" value.isOpen ? 'layui-tree-spread' : '' " v-for="(value,k) in categoryList">
  68. <div class="layui-tree-entry" @mouseover.stop="changeActive(value,k)" @mouseout.stop="removeActive(value,k)">
  69. <div class="layui-tree-main" @click="OpenTree(value,k)">
  70. <span class="layui-tree-iconClick">
  71. <i class="layui-icon layui-icon-triangle-d" v-if="value.child.length && value.isOpen"></i>
  72. <i class="layui-icon layui-icon-triangle-r" v-else-if="value.child.length && !value.isOpen"></i>
  73. <i class="layui-icon " v-else>&nbsp;&nbsp;&nbsp;</i>
  74. </span>
  75. <span class="layui-tree-txt line1" :class="pid == value.id ? 'on': '' " v-text="value.name"></span>
  76. </div>
  77. <div class="layui-btn-group layui-tree-btnGroup layui-layer layui-layer-tips" v-show="value.isShow">
  78. <div>
  79. <i class="layui-icon layui-icon-add-1" @click.stop ="addCategory(value)" title="添加"></i>
  80. <i class="layui-icon layui-icon-edit" @click.stop ="updateCategory(value)" title="编辑"></i>
  81. <i class="layui-icon layui-icon-delete" v-if="!value.child.length" title="删除" @click.stop ="delCategory(value)"></i>
  82. </div>
  83. <i class="layui-layer-TipsG layui-layer-TipsT"></i>
  84. </div>
  85. </div>
  86. <div class="layui-tree-pack layui-tree-lineExtend layui-tree-showLine" v-show="value.isOpen" style="display: block">
  87. <div class="layui-tree-set" v-for="(item,key) in value.child">
  88. <div class="layui-tree-entry">
  89. <div class="layui-tree-main" @click="OpenTree(item,key)">
  90. <span class="layui-tree-iconClick">
  91. <i class="layui-icon"></i>
  92. </span>
  93. <span class="layui-tree-txt line1" :class="pid == item.id ? 'on': '' " v-text="item.name"></span>
  94. </div>
  95. <div class="layui-btn-group layui-tree-btnGroup layui-layer layui-layer-tips" @mouseover.stop ="changeActive(item,k,key)" @mouseout.stop ="removeActive(item,k,key)">
  96. <div>
  97. <i class="layui-icon layui-icon-edit" @click.stop ="updateCategory(item,value.pid)" title="编辑"></i>
  98. <i class="layui-icon layui-icon-delete" @click.stop ="delCategory(item,value.pid)" title="删除"></i>
  99. </div>
  100. <i class="layui-layer-TipsG layui-layer-TipsT"></i>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="layui-col-md10 layui-col-xs10 layui-col-sm10">
  113. <div class="layadmin-homepage-panel layadmin-homepage-shadow">
  114. <div class="layui-card text-center">
  115. <div class="layui-card-header">
  116. <div class="layadmin-homepage-pad-ver" style="text-align: left">
  117. <div class="layui-btn-group">
  118. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" @click="addCategory">添加分类</button>
  119. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" ref="upload">上传图片</button>
  120. <button type="button" class="layui-btn layui-btn-warm layui-btn-sm" :class="selectImages.length ? '':'layui-btn-disabled' " @click="moveCate">移动分类</button>
  121. <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" :class="selectImages.length ? '':'layui-btn-disabled' " @click="delImage">删除图片</button>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="layui-card-body clearfix image-box" style="padding: 10px;height: 360px;z-index:10;">
  126. <div class="layui-col-md2 layui-col-xs2 layui-col-sm2 image" v-for="(item,index) in imageList">
  127. <span class="layui-badge layui-bg-cyan" style="position: absolute;" v-if="item.sort">{{ item.sort }}</span>
  128. <div class="layui-img-box" :class="item.isSelect ? 'on': '' ">
  129. <img :src="item.att_dir" v-if="small == 1" @click="changImage(item)">
  130. <img :src="item.att_dir" v-else @click="changImage(item)">
  131. </div>
  132. </div>
  133. <div class="empty-image" style="width: 100%;height: 100%;text-align: center;" v-if="!imageList.length && loading == false">
  134. <div class="layui-img-box">
  135. <img src="{__ADMIN_PATH}images/empty.jpg" style="height: 400px;" alt="" >
  136. </div>
  137. </div>
  138. </div>
  139. <div class="layui-card-body clearfix page">
  140. <div class="layui-col-md4 layui-col-xs4 layui-col-sm4">
  141. <div class="layui-box" style="margin: 10px 0;">
  142. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" :class="selectImages.length ? '':'layui-btn-disabled' " @click="useImages">使用选中的图片</button>
  143. </div>
  144. </div>
  145. <div class="layui-col-md8 layui-col-xs8 layui-col-sm8 image_page" ref="image_page"></div>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. </body>
  153. </html>
  154. <script src="{__ADMIN_PATH}js/layuiList.js?id=dsfwef"></script>
  155. <script>
  156. var pid = {$pid},small = {$Request.param.small ? : 0} ,parentinputname = '{$Request.param.fodder}';//当前图片分类ID
  157. new Vue({
  158. el: "#app",
  159. data: {
  160. categoryList:[],
  161. searchTitle:'',
  162. pid:pid,
  163. imageList:[],
  164. page:1,
  165. limit:18,
  166. loading:false,
  167. small:small,
  168. selectImages:[],
  169. selectImagesIDS:[],
  170. uploadInst:null,
  171. },
  172. watch:{
  173. page:function () {
  174. this.getImageList();
  175. },
  176. },
  177. methods:{
  178. //删除图片
  179. delImage:function(){
  180. var that=this;
  181. if(!this.selectImages.length) return;
  182. layList.layer.confirm('是否要删除选中图片?', {
  183. btn: ['是的我要删除','我想想把'] //按钮
  184. }, function(){
  185. layList.basePost(that.U({a:'delete'}),{imageid:that.selectImagesIDS},function (res) {
  186. layList.msg(res.msg);
  187. that.selectImagesIDS = [];
  188. that.selectImages = [];
  189. that.getImageList();
  190. },function (res) {
  191. layList.msg(res.msg);
  192. })
  193. })
  194. },
  195. //移动图片分类
  196. moveCate:function(){
  197. if(!this.selectImages.length) return;
  198. return this.getOpenWindow('移动图片',this.U({a:'moveimg'})+'?imgaes='+this.selectImagesIDS);
  199. },
  200. //使用选中图片
  201. useImages:function(){
  202. if(!this.selectImages.length) return;
  203. //判断表单限制图片个数
  204. if(typeof parent.$f != 'undefined'){
  205. //已有图片个数
  206. var nowpics = parent.$f.getValue(parentinputname).length,
  207. props = parent.$f.model()[parentinputname].props || {},
  208. maxlength = props.maxLength || 0;
  209. //已选图片个数
  210. var selectlength = this.selectImages.length;
  211. //还可以选择多少张
  212. var surplus = maxlength-nowpics;
  213. if(nowpics+selectlength > maxlength){
  214. return layList.msg('最多只能选择 '+ surplus +' 张');
  215. }
  216. }
  217. //编辑器中
  218. if(parentinputname == 'editor'){
  219. var list = [];console.log(this.selectImages);
  220. for(var i = 0;i < this.selectImages.length;i++){
  221. list.push({
  222. _src: this.selectImages[i],
  223. src:this.selectImages[i]
  224. });
  225. }
  226. parent.insertEditor(list);
  227. var index = parent.layer.getFrameIndex(window.name);
  228. parent.layer.close(index);
  229. }else{
  230. //form表单中
  231. if(parent.$f){
  232. var value = parent.$f.getValue(parentinputname);//父级input 值
  233. var list = value || [];
  234. for(var i = 0;i < this.selectImages.length;i++){
  235. if(value.indexOf(this.selectImages[i]) == -1) list.push(this.selectImages[i]);
  236. }
  237. parent.$f.changeField(parentinputname,list);
  238. console.log(nowpics);
  239. console.log(maxlength);
  240. console.log(selectlength);
  241. parent.$f.closeModal(parentinputname);
  242. }else{
  243. //独立图片选择页面
  244. if(parentinputname == 'image' && this.selectImages.length > 1) {
  245. return layList.msg('最多只能选择1张');
  246. }
  247. if(parent.$vm){
  248. var rule = parent.$vm.getRule(parentinputname)
  249. if(rule.maxLength !== undefined){
  250. if(this.selectImages.length > rule.maxLength){
  251. return layList.msg('最多只能选择'+rule.maxLength+'张');
  252. }
  253. parent.changeIMG(parentinputname,this.selectImages);
  254. var index = parent.layer.getFrameIndex(window.name);
  255. parent.layer.close(index);
  256. return;
  257. }
  258. }
  259. parent.changeIMG(parentinputname,this.selectImages[0]);
  260. var index = parent.layer.getFrameIndex(window.name);
  261. parent.layer.close(index);
  262. }
  263. }
  264. },
  265. //图片选中和取消
  266. changImage:function(item,index){
  267. this.$set(item,'isSelect',item.isSelect == undefined ? true : !item.isSelect);
  268. var val = small == 1 ? item['satt_dir'] : item['att_dir'];
  269. if(item.isSelect === true) {
  270. this.selectImages[this.selectImages.length] = val;
  271. this.selectImagesIDS[this.selectImages.length] = item['att_id'];
  272. item.sort = this.selectImages.length;
  273. }else{
  274. this.selectImages.splice(this.selectImages.indexOf(val),1);
  275. this.selectImagesIDS.splice(this.selectImages.indexOf(item['att_id']),1);
  276. for (var i=0;i<this.imageList.length;i++){
  277. if(this.imageList[i].sort > item.sort) {
  278. this.imageList[i].sort = (this.imageList[i].sort-1)>=0? this.imageList[i].sort-1 : 0;
  279. }
  280. }
  281. item.sort = 0;
  282. }
  283. // console.log(this.selectImagesIDS)
  284. this.$set(this,'selectImages',this.selectImages);
  285. this.$set(this,'selectImagesIDS',this.selectImagesIDS);
  286. },
  287. //获取图片列表
  288. getImageList:function(){
  289. var that = this;
  290. if(that.loading) return;
  291. that.loading = true;
  292. var index = layList.layer.load(1, {shade: [0.1,'#fff']});
  293. layList.baseGet(this.U({a:'get_image_list',q:{pid:this.pid,page:this.page,limit:this.limit}}),function (res) {
  294. that.loading = false;
  295. that.$set(that,'imageList',res.data.list);
  296. layList.layer.close(index);
  297. if(that.page == 1){
  298. layList.laypage.render({
  299. elem: that.$refs.image_page
  300. ,count: res.data.count
  301. ,limit:that.limit
  302. ,theme: '#1E9FFF',
  303. jump:function (obj) {
  304. that.page=obj.curr;
  305. }
  306. });
  307. }
  308. },function () {
  309. that.loading = false;
  310. layList.layer.close(index);
  311. });
  312. },
  313. //查询分类
  314. search:function(){
  315. // if(!this.searchTitle) return layList.msg('请输入搜索内容!');
  316. this.getCategoryList();
  317. },
  318. //打开和关闭树形
  319. OpenTree:function(item,index){
  320. this.pid = item.id;
  321. if(item.child.length){
  322. item.isOpen == undefined ? false : item.isOpen;
  323. this.$set(this.categoryList[index],'isOpen',!item.isOpen);
  324. }else{
  325. this.page = 1;
  326. this.$set(this,'selectImages',[]);
  327. this.$set(this,'selectImagesIDS',[]);
  328. this.getImageList();
  329. }
  330. this.uploadInst.reload({
  331. url:this.U({a:'upload'})+'?pid='+this.pid
  332. });
  333. },
  334. //组装URL
  335. U:function(opt){
  336. opt = typeof opt == 'object' ? opt : {};
  337. return layList.U({m:'admin',c:"widget.images",a:opt.a || '',q:opt.q || {},p:opt.q || {}});
  338. },
  339. //获取分类
  340. getCategoryList:function(){
  341. var that=this;
  342. layList.baseGet(that.U({a:'get_image_cate',q:{name:this.searchTitle}}),function (res) {
  343. that.$set(that,'categoryList',res.data);
  344. });
  345. },
  346. //鼠标移入显示图标
  347. changeActive:function(item,indexK,index){
  348. if(index)
  349. this.$set(this.categoryList[indexK]['child'],'isShow',true);
  350. else
  351. this.$set(this.categoryList[indexK],'isShow',true);
  352. },
  353. //鼠标移出隐藏
  354. removeActive:function(item,indexK,index){
  355. if(index)
  356. this.$set(this.categoryList[indexK]['child'],'isShow',false);
  357. else
  358. this.$set(this.categoryList[indexK],'isShow',false);
  359. },
  360. //添加分类
  361. addCategory:function (item,pid) {
  362. item = item == undefined ? {} : item;
  363. var id = item.id == undefined ? 0 : item.id,
  364. pid = pid == undefined ? 0 : pid;
  365. return this.getOpenWindow(item.name ? item.name+'编辑' : '新增分类',this.U({a:'addcate',q:{id:pid ==0 ? id : pid }}));
  366. },
  367. //修改分类
  368. updateCategory:function(item,pid){
  369. item = item == undefined ? {} : item ;
  370. pid = pid == undefined ? 0 : pid;
  371. return this.getOpenWindow(item.name+'编辑',this.U({a:'editcate',q:{id:item.id}}));
  372. },
  373. //删除分类
  374. delCategory:function (item,pid) {
  375. var that=this;
  376. if(item.child.length) return layList.msg('请先删除子分类再尝试删除此分类!');
  377. layList.layer.confirm('是否要删除['+item.name+']分类?', {
  378. btn: ['是的我要删除','我想想把'] //按钮
  379. }, function(){
  380. layList.baseGet(that.U({a:'deletecate',q:{id:item.id}}),function (res) {
  381. layList.msg(res.msg,function () {
  382. that.getCategoryList();
  383. });
  384. });
  385. });
  386. },
  387. //打开一个窗口
  388. getOpenWindow:function(title,url,opt){
  389. opt = opt == undefined ? {w:340,h:265} : opt;
  390. return layList.layer.open({
  391. type: 2,
  392. title: title,
  393. shade: [0],
  394. area: [opt.w+"px" , opt.h+'px'],
  395. anim: 2,
  396. content: [url, 'no'],
  397. });
  398. },
  399. //回调
  400. SuccessCateg:function () {
  401. this.getCategoryList();
  402. },
  403. uploal:function () {
  404. var that=this;
  405. this.uploadInst=layList.upload.render({
  406. elem: this.$refs.upload
  407. ,url: this.U({a:'upload'})+'?pid='+this.pid
  408. ,multiple: true
  409. ,auto:true
  410. ,size: 2097152 //限制文件大小,单位 KB
  411. ,done: function(res){
  412. layList.layer.msg(res.msg,{time:3000});
  413. that.getImageList();
  414. }
  415. });
  416. }
  417. },
  418. mounted:function () {
  419. this.getCategoryList();
  420. this.getImageList();
  421. window.SuccessCateg = this.SuccessCateg;
  422. this.uploal();
  423. }
  424. })
  425. </script>