uploadImgList.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <script>
  2. Vue.component('uploadImgList', {
  3. props: ["uploadListShow","name"],
  4. delimiters: ['[[', ']]'],
  5. data(){
  6. return{
  7. imgLoading: false,
  8. thumb_list:[],
  9. image:[],
  10. image_url:[],
  11. ImgList: [],
  12. //弹框上传图片的路径
  13. uploadImg: "",
  14. uploadImgUrl: "",
  15. netImgUrl: "",
  16. chooseImg: "",
  17. radio1: "", //年
  18. radio2: "", //月
  19. activeName2: "first",
  20. //是否显示弹框
  21. pageSize: 0,
  22. current_page: 0,
  23. total: 0,
  24. }
  25. },
  26. watch:{
  27. uploadListShow() {
  28. if(this.uploadListShow) {
  29. this.currentChange(1);
  30. }
  31. }
  32. },
  33. mounted: function(){
  34. // this.currentChange(1);
  35. },
  36. methods:{
  37. chooseTheImg(index,img,img_url) {
  38. console.log(index)
  39. if(this.ImgList[index].checked == 1) {
  40. this.ImgList[index].checked = 0;
  41. }
  42. else {
  43. this.ImgList[index].checked = 1;
  44. }
  45. this.$forceUpdate()
  46. console.log(this.ImgList[index])
  47. },
  48. chooseYear(year) {
  49. this.currentChange(1);
  50. },
  51. chooseMonth(month) {
  52. this.currentChange(1);
  53. },
  54. sureImg() {
  55. if(this.activeName2 == "first") {
  56. this.$emit("sure",this.name,this.image,this.image_url);
  57. }else if(this.activeName2 == "third") {
  58. let arr = [];
  59. let arr_url = [];
  60. this.ImgList.forEach((item,index) => {
  61. if(item.checked == 1) {
  62. arr.push(item.attachment);
  63. arr_url.push(item.url);
  64. }
  65. })
  66. this.$emit("sure",this.name,arr,arr_url);
  67. }
  68. this.beforeClose();
  69. },
  70. // 转化网络地址
  71. transform() {
  72. if(!this.netImgUrl) {
  73. this.$message.error("请输入网络地址")
  74. return;
  75. }
  76. this.imgLoading = true;
  77. this.$http
  78. .post("{!! yzWebFullUrl('upload.uploadV2.fetch') !!}", { url: this.netImgUrl }).then(response => {
  79. if (response.data.result === 1) {
  80. let arr = [];
  81. let arr_url = [];
  82. arr.push(response.data.data.img);
  83. arr_url.push(response.data.data.img_url);
  84. this.$emit("sure",this.name,arr,arr_url);
  85. this.beforeClose();
  86. } else {
  87. this.$message.error(response.data.msg);
  88. this.beforeClose();
  89. }
  90. this.imgLoading = false;
  91. })
  92. .catch(err => {
  93. console.error(err);
  94. this.imgLoading = false;
  95. });
  96. },
  97. currentChange(val) {
  98. this.imgLoading = true;
  99. this.$http.post("{!! yzWebFullUrl('upload.uploadV2.get-image') !!}"+'&group_id=-999&local=local',{ page: val, year: this.radio1, month: this.radio2 })
  100. .then(response => {
  101. if (response.data.result == 1) {
  102. this.total = response.data.data.total;
  103. this.ImgList = response.data.data.data;
  104. this.ImgList.forEach((item,index) => {
  105. this.ImgList[index].checked = 0;
  106. })
  107. this.current_page = response.data.data.current_page;
  108. this.pageSize = response.data.data.per_page;
  109. } else {
  110. this.$message.error(response.data.msg);
  111. }
  112. this.imgLoading = false;
  113. })
  114. .catch(err => {
  115. console.error(err);
  116. this.imgLoading = false;
  117. });
  118. },
  119. deleteImg(id) {
  120. this.imgLoading = true;
  121. this.$http
  122. .post("{!! yzWebFullUrl('upload.uploadV2.delete') !!}", { id: id })
  123. .then(response => {
  124. if (response.data.result == 1) {
  125. this.$message.success("系统删除成功");
  126. this.currentChange(1);
  127. } else {
  128. this.$message.error(response.data.msg);
  129. }
  130. this.imgLoading = false;
  131. })
  132. .catch(err => {
  133. console.error(err);
  134. this.imgLoading = false;
  135. });
  136. },
  137. beforeUpload(file) {
  138. this.imgLoading = true;
  139. const isLt2M = file.size / 1024 / 1024 < 4;
  140. if (!isLt2M) {
  141. this.$message.error("上传图片大小不能超过 4MB!");
  142. this.imgLoading = false;
  143. }
  144. return isLt2M;
  145. },
  146. uploadBannerSuccess (res,file) {
  147. console.log(res)
  148. if (res.result == 1) {
  149. if (res.data.state == 'SUCCESS') {
  150. this.uploadImg = res.data.attachment;//传相对地址
  151. this.uploadImgUrl = res.data.url;
  152. this.$message.success("上传成功!");
  153. this.image.push(res.data.attachment);
  154. this.image_url.push(res.data.url);
  155. } else {
  156. this.$message.error(res.msg);
  157. }
  158. } else {
  159. this.$message.error(res.msg);
  160. }
  161. this.imgLoading = false;
  162. },
  163. clearImgList(file, fileList) {
  164. let arr = [];
  165. let arr_url = [];
  166. console.log(fileList)
  167. for(var i=0;i<fileList.length;i++){
  168. arr.push(fileList[i].response.data.attachment);
  169. arr_url.push(fileList[i].response.data.url);
  170. }
  171. this.image = arr;
  172. this.image_url = arr_url;
  173. },
  174. initData(){
  175. this.imgLoading= false;
  176. this.ImgList= [];
  177. this.image = [];
  178. this.image_url = [];
  179. this.thumb_list = [];
  180. this.uploadImg= "";
  181. this.uploadImgUrl= "";
  182. this.netImgUrl= "";
  183. this.chooseImg= "";
  184. this.radio1= ""; //年
  185. this.radio2= ""; //月
  186. this.activeName2= "first";
  187. this.pageSize= 0;
  188. this.current_page= 0;
  189. this.total= 0;
  190. },
  191. beforeClose() {
  192. this.initData();
  193. this.$emit('replace', this.uploadListShow);
  194. },
  195. },
  196. template: `
  197. <el-dialog :visible.sync="uploadListShow" width="60%" center :before-close="beforeClose">
  198. <el-tabs v-model="activeName2" type="card">
  199. <el-tab-pane label="上传图片" name="first">
  200. <div
  201. style="text-align: center;margin-top: 15px;"
  202. v-loading="imgLoading"
  203. element-loading-background="rgba(0, 0, 0, 0)"
  204. >
  205. <el-upload
  206. action="{!!yzWebFullUrl('upload.uploadV2.upload',['upload_type'=>'image'])!!}"
  207. list-type="picture-card"
  208. :file-list="thumb_list"
  209. multiple
  210. accept="image/*"
  211. :on-success="uploadBannerSuccess"
  212. :on-remove="clearImgList"
  213. :before-upload="beforeUpload"
  214. >
  215. <i class="el-icon-plus"></i>
  216. </el-upload>
  217. </div>
  218. </el-tab-pane>
  219. <el-tab-pane label="提取网络图片" name="second">
  220. <el-input
  221. v-model="netImgUrl"
  222. placeholder="请输入网络图片地址"
  223. style="width:90%"
  224. ></el-input>
  225. <el-button @click="transform">转化</el-button>
  226. </el-tab-pane>
  227. <el-tab-pane label="浏览图片" name="third">
  228. <div>
  229. <el-radio-group v-model="radio1" size="medium" @change="chooseYear">
  230. <el-radio-button label="">不限</el-radio-button>
  231. <el-radio-button label="2021">2021年</el-radio-button>
  232. <el-radio-button label="2020">2020年</el-radio-button>
  233. <el-radio-button label="2019">2019年</el-radio-button>
  234. <el-radio-button label="2018">2018年</el-radio-button>
  235. <el-radio-button label="2017">2017年</el-radio-button>
  236. <el-radio-button label="2016">2016年</el-radio-button>
  237. </el-radio-group>
  238. </div>
  239. <div style="margin-top: 10px;">
  240. <el-radio-group v-model="radio2" size="small" @change="chooseMonth">
  241. <el-radio-button label="">不限</el-radio-button>
  242. <el-radio-button label="1">1月</el-radio-button>
  243. <el-radio-button label="2">2月</el-radio-button>
  244. <el-radio-button label="3">3月</el-radio-button>
  245. <el-radio-button label="4">4月</el-radio-button>
  246. <el-radio-button label="5">5月</el-radio-button>
  247. <el-radio-button label="6">6月</el-radio-button>
  248. <el-radio-button label="7">7月</el-radio-button>
  249. <el-radio-button label="8">8月</el-radio-button>
  250. <el-radio-button label="9">9月</el-radio-button>
  251. <el-radio-button label="10">10月</el-radio-button>
  252. <el-radio-button label="11">11月</el-radio-button>
  253. <el-radio-button label="12">12月</el-radio-button>
  254. </el-radio-group>
  255. </div>
  256. <div id="upload-img" class="imgList" v-loading="imgLoading" element-loading-background="rgba(0, 0, 0, 0)">
  257. <div class="avatar-uploader-box" v-for="(img,index) in ImgList" :key="index">
  258. <img
  259. @click="chooseTheImg(index,img.attachment,img.url)"
  260. :src="img.url"
  261. class="avatar"
  262. :style="{border:(img.checked==1?'2px #409EFF solid':'0')}"
  263. />
  264. <i
  265. class="el-icon-circle-close"
  266. @click="deleteImg(img.id)"
  267. title="点击清除图片"
  268. ></i>
  269. <i class="el-icon-check" v-show="img.checked==1"
  270. style="background: #409EFF;color: #fff;bottom: 0px;font-weight: 600;font-size: 30px;position: absolute;right: 9px;
  271. "></i>
  272. </div>
  273. </div>
  274. <el-pagination
  275. style="margin-top: 10px;text-align: right"
  276. background
  277. @current-change="currentChange"
  278. :page-size="pageSize"
  279. :current-page.sync="current_page"
  280. :total="total"
  281. layout="prev, pager, next"
  282. >
  283. </el-pagination>
  284. </el-tab-pane>
  285. </el-tabs>
  286. <span slot="footer" class="dialog-footer">
  287. <el-button @click="beforeClose">取 消</el-button>
  288. <el-button type="primary" @click="sureImg">确 定 </el-button>
  289. </span>
  290. </el-dialog>
  291. `
  292. });
  293. </script>