qlg.tsgz.moe/hyhproject/home/view/default/shops/shopcats/shopcats webuploader╔╧┤лoss.js
2019-09-06 23:53:10 +08:00

401 lines
12 KiB
JavaScript
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function addCat(obj,p,catNo){
var html = new Array();
if(typeof(obj)=="number"){
$("#cat_list_tab").append($("#cat_p_tr").html());
}else{
var className = (p==0)?"tr_c_new":"tr_"+catNo+" tr_0";
var gettpl = $("#cat_c_tr").html();
laytpl(gettpl).render({"className":className,"p":p}, function(html){
$(obj).parent().parent().parent().append(html);
});
}
$('.wst-shop-but').show();
}
function delCatObj(obj,vk){
if(vk==1){
$(obj).parent().parent().parent().remove();
}else{
$(obj).parent().parent().remove();
}
if($(".tr_0").size()==0 && $(".tbody_new").size()==0)$('.wst-shop-but').hide();
}
function treeCatOpen(obj,id){
if( $(obj).attr('class').indexOf('active') > -1 ){
$(obj).removeClass('active');
$(obj).html('<img class="wst-lfloat" style="margin-top:-3px;" src="'+WST.conf.ROOT+'/hyhproject/home/view/default/img/seller_icon_sq.png">');
$('.tree_'+id).hide();
}else{
$(obj).addClass('active');
$(obj).html('<img class="wst-lfloat" style="margin-top:-3px;" src="'+WST.conf.ROOT+'/hyhproject/home/view/default/img/seller_icon_zk.png">');
$('.tree_'+id).show();
}
}
function delCat(id){
var box = WST.confirm({content:"您确定要删除该商品分类吗?",yes:function(){
var loading = WST.msg('正在提交数据,请稍后...', {icon: 16,time:60000});
$.post(WST.U('home/shopcats/del'),{id:id},function(data,textStatus){
layer.close(loading);
var json = WST.toJson(data);
if(json.status=='1'){
WST.msg("操作成功",{icon:1});
layer.close(box);
location.reload();
}else{
WST.msg(json.msg,{icon:2});
}
});
}});
}
function batchSaveCats(){
var params = {};
var fristNo = 0;
var secondNo = 0;
$(".tbody_new").each(function(){
secondNo = 0;
var pobj = $(this).find(".tr_new");
params['catName_'+fristNo] = $.trim(pobj.find(".catname").val());
if(params['catName_'+fristNo]==''){
WST.msg('请输入商品分类名称!', {icon: 5});
return;
}
params['catSort_'+fristNo] = pobj.find(".catsort").val();
params['catShow_'+fristNo] = pobj.find(".catshow").prop("checked")?1:0
$(this).find(".tr_c_new").each(function(){
params['catId_'+fristNo+'_'+secondNo] = fristNo;
params['catName_'+fristNo+'_'+secondNo] = $.trim($(this).find(".catname").val());
if(params['catName_'+fristNo+'_'+secondNo]==''){
WST.msg('请输入商品分类名称!', {icon: 5});
return;
}
params['catSort_'+fristNo+'_'+secondNo] = $(this).find(".catsort").val();
params['catShow_'+fristNo+'_'+secondNo] = $(this).find(".catshow").prop("checked")?1:0
params['catSecondNo_'+fristNo] = ++secondNo;
});
params['fristNo'] = ++fristNo;
});
var otherNo = 0;
$(".tr_0").each(function(){
params['catId_o_'+otherNo] = $(this).attr('catId');
params['catName_o_'+otherNo] = $.trim($(this).find(".catname").val());
if(params['catName_o_'+otherNo]==''){
WST.msg('请输入商品分类名称!', {icon: 5});
return;
}
params['catSort_o_'+otherNo] = $(this).find(".catsort").val();
params['catShow_o_'+otherNo] = $(this).find(".catshow").prop("checked")?1:0;
params['otherNo'] = ++otherNo;
});
$.post(WST.U('home/shopcats/batchSaveCats'),params,function(data,textStatus){
var json = WST.toJson(data);
if(json.status==1){
WST.msg('新增成功!', {icon: 1,time:500},function(){
location.reload();
});
}else{
WST.msg('新增失败!', {icon: 5});
}
});
}
function editCatName(obj){
$.post(WST.U('home/shopcats/editName'),{"id":$(obj).attr('dataId'),"catName":obj.value},function(data,textStatus){
var json = WST.toJson(data);
if(json.status=='1'){
WST.msg('操作成功!',{icon: 1,time:500});
}else{
WST.msg('操作失败!', {icon: 5});
}
});
}
function editCatSort(obj){
$.post(WST.U('home/shopcats/editSort'),{"id":$(obj).attr('dataId'),"catSort":obj.value},function(data,textStatus){
var json = WST.toJson(data);
if(json.status=='1'){
WST.msg('操作成功!',{icon: 1,time:500});
}else{
WST.msg('操作失败!', {icon: 5});
}
});
}
function changeCatStatus(isShow,id,pid){
var params = {};
params.id = id;
params.isShow = isShow;
params.pid = pid;
$.post(WST.U('home/shopcats/changeCatStatus'),params,function(data,textStatus){
location.reload();
});
}
//mark 修改特产省份 20180518 by zll
var isInitUpload = false;
function setSpecial(catId,provId,catImg,isHot){
if(provId>0)$('#provId').val(provId);
if(catImg !=''){
$('#preview').html('<img src="'+WST.conf.IMGURL+'/'+catImg+'" height="75px" />');
$('#catImg').val(catImg);
}else{
$('#preview').html('');
$('#catImg').val('');
};
(isHot==1)?$('#isHot').prop('checked',true):$('#isHot').prop('checked',false);
if(!isInitUpload)initUpload();
var box = layer.open({
type:1,
title:'设置特产省份',
btn:['设置','消除特产','取消'],
content:$('#shopcatsBox'),
area:['400px','500px'],
yes:function(){
var params = WST.getParams('.ipt');
params.provName = $('#provId option:selected').text();
params.catId = catId;
if(params.provId == '0'){
layer.msg('请选择省份');
return false;
}
if(params.catImg==''){
layer.msg('请选择图片');
return false;
}
$.post(WST.U('home/shopcats/setSpecial'),params,function(data){
var json = WST.toJson(data);
if(json.status == '1'){
WST.msg(json.msg,{icon:1});
layer.close(box);
window.parent.location.reload();
}else{
WST.msg(json.msg,{icon:2})
}
});
},
btn2:function(){
var params = {};
params.catId = catId;
params.provName='';
params.provId = '0';
params.isHot = '0';
params.catImg = '';
$.post(WST.U('home/shopcats/setSpecial'),params,function(data){
var json = WST.toJson(data);
if(json.status == '1'){
WST.msg(json.msg,{icon:1});
window.location.reload();
}else{
WST.msg(json.msg,{icon:2})
}
});
},
});
}
// function initUpload(){
// isInitUpload = true;
// //文件上传
// WST.upload({
// pick:'#catFilePicker',
// formData: {dir:'shopcats'},
// accept: {extensions: 'gif,jpg,jpeg,png',mimeTypes: 'image/jpg,image/jpeg,image/png,image/gif'},
// callback:function(f){
// var json = WST.toJson(f);
// if(json.status==1){
// $('#uploadMsg').empty().hide();
// //将上传的图片路径赋给全局变量
// $('#catImg').val(json.savePath+json.thumb);
// $('#preview').html('<img src="'+WST.conf.ROOT+'/'+json.savePath+json.thumb+'" height="75" />');
// }else{
// WST.msg(json.msg,{icon:2});
// }
// },
// progress:function(rate){
// $('#uploadMsg').show().html('已上传'+rate+"%");
// }
// });
// }
accessid = '';
accesskey = '';
host = '';
policyBase64 = '';
signature = '';
callbackbody = '';
filename = '';
key = '';
expire = 0;
g_object_name = '';
g_object_name_type = '';
now = timestamp = Date.parse(new Date()) / 1000;
dir = 'test';
function send_request()
{
var xmlhttp = null;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
// serverUrl = './php/get.php?dir='+dir
xmlhttp.open( "GET", "http://localhost/oss/get.php?dir="+dir, false );
xmlhttp.send( null );
return xmlhttp.responseText
}
else
{
alert("Your browser does not support XMLHTTP.");
}
};
// function check_object_radio() {
// var tt = document.getElementsByName('myradio');
// for (var i = 0; i < tt.length ; i++ )
// {
// if(tt[i].checked)
// {
// g_object_name_type = tt[i].value;
// break;
// }
// }
// }
function get_signature()
{
//可以判断当前expire是否超过了当前时间,如果超过了当前时间,就重新取一下.3s 做为缓冲
now = timestamp = Date.parse(new Date()) / 1000;
if (expire < now + 3)
{
body = send_request();
var obj = eval ("(" + body + ")");
host = obj['host']
policyBase64 = obj['policy']
accessid = obj['accessid']
signature = obj['signature']
expire = parseInt(obj['expire'])
callbackbody = obj['callback']
key = obj['dir']
return true;
}
return false;
};
function random_string(len) {
  len = len || 32;
  var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  var maxPos = chars.length;
  var pwd = '';
  for (i = 0; i < len; i++) {
  pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function get_suffix(filename) {
pos = filename.lastIndexOf('.')
suffix = ''
if (pos != -1) {
suffix = filename.substring(pos)
}
return suffix;
}
function calculate_object_name(filename)
{
suffix = get_suffix(filename);
g_object_name = key + random_string(10) + suffix;
return '';
}
function get_uploaded_object_name(filename)
{
return g_object_name;
}
function set_upload_param(up, filename, ret)
{
if (ret == false)
{
ret = get_signature();
}
g_object_name = key;
if (filename != '') {
suffix = get_suffix(filename)
calculate_object_name(filename)
}
new_multipart_params = {
'key' : g_object_name,
'policy': policyBase64,
'OSSAccessKeyId':accessid ,
// 'success_action_status' : '200', //让服务端返回200,不然默认会返回204
'callback' : callbackbody,
'signature': signature,
};
up.option('server',host);
up.option('formData',new_multipart_params);
console.log(up.option());
up.upload();
}
function initUpload(){
isInitUpload = true;
//文件上传
uploader = new WebUploader.create({
pick:'#catFilePicker',
auto: true,
swf: WST.conf.ROOT +'/plugins/webuploader/Uploader.swf',
server:'http://heyuanhui.oss-cn-qingdao.aliyuncs.com',
accept: {extensions: 'gif,jpg,jpeg,png',mimeTypes: 'image/jpg,image/jpeg,image/png,image/gif'},
});
uploader.on('beforeFileQueued',function(file){
set_upload_param(uploader,'',false);
});
// uploader.on('uploadBeforeSend', function(obj,data, headers) {
// // console.log(obj.file);
// set_upload_param(uploader,obj.file.name,true);
// });
uploader.on('uploadStart',function(file){
set_upload_param(uploader,file.name,true);
});
uploader.on('uploadSuccess', function(file,response) {
console.log(response);
pic_name = get_uploaded_object_name(file.name)
console.log(pic_name);
$('#uploadMsg').empty().hide();
//将上传的图片路径赋给全局变量
$('#catImg').val(pic_name);
$('#preview').html('<img src="http://img.juzi199.com/'+pic_name+'" height="75"/>');
});
uploader.on('uploadError', function( file ) {
console.log(2222);
});
uploader.on( 'uploadProgress', function( file, percentage ) {
// console.log(file);
rate = percentage.toFixed(2)*100;
$('#uploadMsg').show().html('已上传'+rate+"%");
});
}
//end