uploadfile.blade.php 9.0 KB

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