1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| var common = {
| layuiForm: null, layuiUpload: null, layuiElement: null,
| layuiLayer: null,
| $: null,
| initLayui(callback) {
| console.log("开始初始化");
| layui.use(['form', 'upload', 'element', 'layer', 'jquery'], function () {
| common.$ = layui.jquery
| , common.layuiUpload = layui.upload
| , common.layuiElement = layui.element
| , common.layuiLayer = layui.layer
| , common.layuiForm = layui.form;
| common.layuiForm.verify({
| decimal: [/^(?:[1-9][0-9]*\.[0-9]+|0\.(?!0+$)[0-9]+|0)$/, '请输入数字'],
| integer: [/^\+?[1-9][0-9]*$/, '请输入正整数'],
| });
|
| console.log("初始化完成")
| callback();
| });
| },
| initLayuiForm: function (form) {
| form.verify({
| decimal: [/^(?:[1-9][0-9]*\.[0-9]+|0\.(?!0+$)[0-9]+|0)$/, '请输入数字'],
| integer: [/^\+?[1-9][0-9]*$/, '请输入正整数'],
| });
| }
| ,
| openEditDialog: function (params) {
| var layerIndex = layer.open({
| title: params.title,
| type: 2,
| area: [params.width + 'px', params.height + 'px'],
| shade: 0.3,
| shadeClose: false,//默认开启遮罩关闭
| resize: false,//默认重设大小是否
| content: params.content,
| //如果不让iframe出现滚动条,
| //可以content: ['http://sentsin.com', 'no']
| btn: [params.sure ? params.sure : '确定'],
| yes: function (index) {
| //获取选择的row,并加载到页面
| window["layui-layer-iframe" + index].submit(function (res) {
| if (params.submit) {
| params.submit(res);
| }
| });
| },
| cancel: function () {
| //右上角关闭回调
| if (params.close) {
| params.close();
| }
| }
| });
| return layerIndex;
| }
| ,
| closeDialog(index) {
| layer.close(index);
| }
| ,
| getQueryString(name) {
| var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
| var r = window.location.search.substr(1).match(reg);
| if (r != null) return unescape(r[2]);
| return null;
| }
| ,
| //初始化图片上传插件
| initUploadImagePlugin(params) {
| console.log(params);
| params.data = {
| dir: params.dir
| }
| //普通图片上传
| var uploadInst = common.layuiUpload.render({
| elem: params.elem,
| //自动上传图片
| auto: false,
| data: params.data,
| url: params.uploadUrl,
| field: params.field ? params.field : 'image',
| accept: 'images',
| acceptMime: 'image/*',
| multiple: params.multiple ? true : false
| , choose: function (obj) {
| if (params.choose) {
| params.choose(obj)
| return;
| }
| //预读本地文件示例,不支持ie8
| obj.preview(function (index, file, result) {
| $(params.showElem).attr('src', result); //图片链接(base64)
| });
| },
| done: function (res, index, upload) { //上传后的回调
| console.log("上传成功");
| console.log(res);
| if (res.code == 0) {
| params.uploadSuccess(res);
| } else {
| layer.alert(res.msg, {icon: 5}, null);
| }
| },
| error: function () {
| layer.alert("图片上传失败", {icon: 5}, null);
| if (params.uploadFail) {
| params.uploadFail();
| }
| }
|
| });
|
| return uploadInst;
| },
| notify: {
| error(msg) {
| layer.msg(msg, {icon: 5, anim: 6});
| }
|
|
| }
| }
| ;
|
|