images.php 25 KB

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