watermark.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. layui.use(['form','layer','laydate','table','laytpl','layedit','upload'],function(){
  2. var form = layui.form,
  3. layer = parent.layer === undefined ? layui.layer : top.layer,
  4. $ = layui.jquery,
  5. table = layui.table,
  6. upload = layui.upload;
  7. //添加图片上传
  8. upload.render({
  9. elem: '#test1'
  10. ,url: '/house/createimg'
  11. ,data:{token:csrfToken}
  12. ,field:'img'
  13. ,auto:false
  14. ,bindAction:'#addcity'
  15. ,choose: function(obj){
  16. obj.preview(function(index, file, result){
  17. $('#demo1').attr('src', result); //图片链接(base64)
  18. });
  19. }
  20. });
  21. // 点击放大图片
  22. $('#demo1').on('click', function(){
  23. var _src = $(this).attr('src');
  24. layui.layer.open({
  25. type: 1,
  26. title: false, //是否显示标题
  27. area: ['60%', '80%'],
  28. shade: 0.6, //透明度
  29. closeBtn: 1, //按钮 1有,0无
  30. shadeClose: true,
  31. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  32. });
  33. });
  34. form.on('submit(watermark)',function (data) {
  35. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  36. var formData = new FormData($('#start_form')[0]);
  37. $.ajax({
  38. cache : true,
  39. type : "post",
  40. url : "/watermark/aa",
  41. data : formData, // 你的formid
  42. async : false,
  43. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  44. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  45. error : function(request) {
  46. top.layer.close(index); //关闭数据提交信息
  47. layer.alert("网络超时");
  48. },
  49. success : function(data) {
  50. top.layer.close(index); //关闭数据提交信息
  51. if (data.code == 200) {
  52. layer.msg(data.msg);
  53. parent.layui.table.reload('tablerReload');
  54. } else if(data.code == 300){
  55. layer.msg(data.msg);
  56. layer.msg(ReturnInfo(data.data),{icon:5});
  57. }
  58. }
  59. });
  60. return false;
  61. })
  62. })