Commit fcb6f59c authored by shajiaiming's avatar shajiaiming

添加图片选项

parent 80f2bde6
......@@ -16,6 +16,7 @@ class ArticleForm extends Model
public $title;
public $url;
public $status;
public $image_url;
public function formName()
{
......@@ -25,15 +26,16 @@ class ArticleForm extends Model
public function rules()
{
return [
[['title', 'url'], 'required', 'on' => 'add'],
[['id', 'title', 'url'], 'required', 'on' => 'edit'],
[['title','image_url'], 'required', 'on' => 'add'],
[['id', 'title'], 'required', 'on' => 'edit'],
[['url'], 'safe']
];
}
public function scenarios()
{
return [
'add' => ['title', 'url', 'status'],
'add' => ['title', 'url', 'status', 'image_url'],
'edit' => ['id', 'title', 'url', 'status'],
];
}
......
......@@ -26,8 +26,7 @@
<div class="layui-form-item">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">外链地址</label>
<div class="layui-input-block">
<input class="layui-input" type="text" value="<?= $model->url ?>" lay-verify="required|url"
name="url">
<input class="layui-input" type="text" value="<?= $model->url ?>" name="url">
</div>
</div>
......@@ -40,7 +39,20 @@
</select>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px" id="icon1">
</div>
<input type="hidden" name="image_url" value="" lay-verify="required|image_url">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn" lay-submit>保存</button>
</div>
......@@ -50,4 +62,21 @@
<script>
var form = layui.form;
form.render(null, 'form1');
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf, image_type: 2},
done: function (res) {
if (res.code == 0) {
$("input[name='image_url']").val(res.data.image_src);
$("#icon1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
</script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment