python学习

This commit is contained in:
2019-08-02 14:39:05 +08:00
parent c09984ab48
commit f1a754820c
14 changed files with 758 additions and 224 deletions

52
web/static/js/food/cat.js Normal file
View File

@@ -0,0 +1,52 @@
;
var food_cat_ops = {
init:function(){
this.eventBind();
},
eventBind:function(){
var that = this;
$(".wrap_search select[name=status]").change(function(){
$(".wrap_search").submit();
});
$(".remove").click( function(){
that.ops( "remove",$(this).attr("data") );
} );
$(".recover").click( function(){
that.ops( "recover",$(this).attr("data") );
} );
},
ops:function( act,id ){
var callback = {
'ok':function(){
$.ajax({
url:common_ops.buildUrl( "/food/cat-ops" ),
type:'POST',
data:{
act:act,
id:id
},
dataType:'json',
success:function( res ){
var callback = null;
if( res.code == 200 ){
callback = function(){
window.location.href = window.location.href;
}
}
common_ops.alert( res.msg,callback );
}
});
},
'cancel':null
};
common_ops.confirm( ( act == "remove" ? "确定删除?":"确定恢复?" ), callback );
}
};
$(document).ready( function(){
food_cat_ops.init();
} );

View File

@@ -0,0 +1,62 @@
;
var food_cat_set_ops = {
init:function(){
this.eventBind();
},
eventBind:function(){
$(".wrap_cat_set .save").click(function(){
var btn_target = $(this);
if( btn_target.hasClass("disabled") ){
common_ops.alert("正在处理!!请不要重复提交~~");
return;
}
var name_target = $(".wrap_cat_set input[name=name]");
var name = name_target.val();
var weight_target = $(".wrap_cat_set input[name=weight]");
var weight = weight_target.val();
if( name.length < 1 ){
common_ops.tip( "请输入符合规范的分类名称~~",name_target );
return false;
}
if( parseInt( weight ) < 1 ){
common_ops.tip( "请输入符合规范的权重并且至少要大于1~~",weight_target );
return false;
}
btn_target.addClass("disabled");
var data = {
name: name,
weight: weight,
id:$(".wrap_cat_set input[name=id]").val()
};
$.ajax({
url:common_ops.buildUrl( "/food/cat-set" ),
type:'POST',
data:data,
dataType:'json',
success:function( res ){
btn_target.removeClass("disabled");
var callback = null;
if( res.code == 200 ){
callback = function(){
window.location.href = common_ops.buildUrl("/food/cat");
}
}
common_ops.alert( res.msg,callback );
}
});
});
}
};
$(document).ready( function(){
food_cat_set_ops.init();
} );

View File

@@ -0,0 +1,50 @@
;
var food_index_ops = {
init:function(){
this.eventBind();
},
eventBind:function(){
var that = this;
$(".remove").click( function(){
that.ops( "remove",$(this).attr("data") )
});
$(".recover").click( function(){
that.ops( "recover",$(this).attr("data") )
});
$(".wrap_search .search").click( function(){
$(".wrap_search").submit();
});
},
ops:function( act,id ){
var callback = {
'ok':function(){
$.ajax({
url:common_ops.buildUrl("/food/ops"),
type:'POST',
data:{
act:act,
id:id
},
dataType:'json',
success:function( res ){
var callback = null;
if( res.code == 200 ){
callback = function(){
window.location.href = window.location.href;
}
}
common_ops.alert( res.msg,callback );
}
});
},
'cancel':null
};
common_ops.confirm( ( act=="remove" )?"确定删除?":"确定恢复?",callback );
}
};
$(document).ready( function(){
food_index_ops.init();
});

173
web/static/js/food/set.js Normal file
View File

@@ -0,0 +1,173 @@
;
var upload = {
error: function (msg) {
common_ops.alert(msg);
},
success: function (file_key) {
if (!file_key) {
return;
}
var html = '<img src="' + common_ops.buildPicUrl(file_key) + '"/>'
+ '<span class="fa fa-times-circle del del_image" data="' + file_key + '"></span>';
if ($(".upload_pic_wrap .pic-each").size() > 0) {
$(".upload_pic_wrap .pic-each").html(html);
} else {
$(".upload_pic_wrap").append('<span class="pic-each">' + html + '</span>');
}
food_set_ops.delete_img();
}
};
var food_set_ops = {
init: function () {
this.ue = null;
this.eventBind();
this.initEditor();
this.delete_img();
},
eventBind: function () {
var that = this;
$(".wrap_food_set .upload_pic_wrap input[name=pic]").change(function () {
$(".wrap_food_set .upload_pic_wrap").submit();
});
$(".wrap_food_set select[name=cat_id]").select2({
language: "zh-CN",
width: '100%'
});
$(".wrap_food_set input[name=tags]").tagsInput({
width: 'auto',
height: 40,
onAddTag: function (tag) {
},
onRemoveTag: function (tag) {
}
});
$(".wrap_food_set .save").click(function () {
var btn_target = $(this);
if (btn_target.hasClass("disabled")) {
common_ops.alert("正在处理!!请不要重复提交~~");
return;
}
var cat_id_target = $(".wrap_food_set select[name=cat_id]");
var cat_id = cat_id_target.val();
var name_target = $(".wrap_food_set input[name=name]");
var name = name_target.val();
var price_target = $(".wrap_food_set input[name=price]");
var price = price_target.val();
var summary = $.trim(that.ue.getContent());
var stock_target = $(".wrap_food_set input[name=stock]");
var stock = stock_target.val();
var tags_target = $(".wrap_food_set input[name=tags]");
var tags = $.trim(tags_target.val());
if (parseInt(cat_id) < 1) {
common_ops.tip("请选择分类~~", cat_id_target);
return;
}
if (name.length < 1) {
common_ops.alert("请输入符合规范的名称~~");
return;
}
if (parseFloat(price) <= 0) {
common_ops.tip("请输入符合规范的售卖价格~~", price_target);
return;
}
if ($(".wrap_food_set .pic-each").size() < 1) {
common_ops.alert("请上传封面图~~");
return;
}
if (summary.length < 10) {
common_ops.tip("请输入描述并不能少于10个字符~~", price_target);
return;
}
if (parseInt(stock) < 1) {
common_ops.tip("请输入符合规范的库存量~~", stock_target);
return;
}
if (tags.length < 1) {
common_ops.alert("请输入标签,便于搜索~~");
return;
}
btn_target.addClass("disabled");
var data = {
cat_id: cat_id,
name: name,
price: price,
main_image: $(".wrap_food_set .pic-each .del_image").attr("data"),
summary: summary,
stock: stock,
tags: tags,
id: $(".wrap_food_set input[name=id]").val()
};
$.ajax({
url: common_ops.buildUrl("/food/set"),
type: 'POST',
data: data,
dataType: 'json',
success: function (res) {
btn_target.removeClass("disabled");
var callback = null;
if (res.code == 200) {
callback = function () {
window.location.href = common_ops.buildUrl("/food/index");
}
}
common_ops.alert(res.msg, callback);
}
});
});
},
initEditor: function () {
var that = this;
that.ue = UE.getEditor('editor', {
toolbars: [
['undo', 'redo', '|',
'bold', 'italic', 'underline', 'strikethrough', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight'],
['customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'directionalityltr', 'directionalityrtl', 'indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
'link', 'unlink'],
['imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'insertimage', 'insertvideo', '|',
'horizontal', 'spechars', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols']
],
enableAutoSave: true,
saveInterval: 60000,
elementPathEnabled: false,
zIndex: 4,
serverUrl: common_ops.buildUrl('/upload/ueditor')
});
},
delete_img: function () {
$(".wrap_food_set .del_image").unbind().click(function () {
$(this).parent().remove();
});
}
};
$(document).ready(function () {
food_set_ops.init();
});