Commit 7e16372771d1b888f4bd0c3e12633c3e5fae34b7

Authored by pengye
1 parent add748cf

菜品管理--改为上传至七牛云,在新增或者修改传网络地址

1 //logs.js 1 //logs.js
2 var util = require('../../utils/util.js') 2 var util = require('../../utils/util.js')
3 var uri=require('../../utils/uri.js') 3 var uri=require('../../utils/uri.js')
  4 +import App from '../../utils/api.js'
4 5
5 Page({ 6 Page({
6 data: { 7 data: {
@@ -15,7 +16,8 @@ Page({ @@ -15,7 +16,8 @@ Page({
15 price:'', 16 price:'',
16 member_price:'', 17 member_price:'',
17 status:1, 18 status:1,
18 - moresetting:true 19 + moresetting:true,
  20 + token: '',
19 }, 21 },
20 onLoad:function(opt){ 22 onLoad:function(opt){
21 var that=this; 23 var that=this;
@@ -46,7 +48,13 @@ Page({ @@ -46,7 +48,13 @@ Page({
46 } 48 }
47 console.log(this.data.id) 49 console.log(this.data.id)
48 this.switchstatus=this.selectComponent('#switch'); 50 this.switchstatus=this.selectComponent('#switch');
49 - 51 + // 获取七牛云token
  52 + App.Qiniu.GetUploadToken().then(res => {
  53 + let token = res.data.token
  54 + this.setData({
  55 + token
  56 + })
  57 + })
50 }, 58 },
51 onShow:function(){ 59 onShow:function(){
52 if(util.cache('spec')){ 60 if(util.cache('spec')){
@@ -432,34 +440,19 @@ Page({ @@ -432,34 +440,19 @@ Page({
432 var that=this; 440 var that=this;
433 if(this.data.tempimage){ 441 if(this.data.tempimage){
434 var that=this; 442 var that=this;
435 - wx.uploadFile({  
436 - url: "https://xt03.colorcun.com/?s=App.Goods.UploadImg",  
437 - filePath: this.data.tempimage,  
438 - name: "file",  
439 - header: {  
440 - 'content-type': 'multipart/form-data'  
441 - }, // 设置请求的 header  
442 - success: function (res) {  
443 - console.log(res)  
444 - if(res.statusCode==200){  
445 - var img=JSON.parse(res.data).data[0]  
446 - console.log(img)  
447 - that.setData({  
448 - image:img  
449 - })  
450 - formdata['image']=img  
451 - //有id,为修改;若无,为添加  
452 - if(that.data.id){  
453 - that.changeFood(formdata)  
454 - }else{  
455 - that.addFood(formdata)  
456 - }  
457 - }  
458 - },  
459 - fail: function (res){  
460 - console.log(res); 443 + util.uploadFile(this.data.tempimage, this.data.token, 'flyDuckDish').then(res => {
  444 + console.log(res);
  445 + that.setData({
  446 + image:res
  447 + })
  448 + formdata['image']=res
  449 + //有id,为修改;若无,为添加
  450 + if(that.data.id){
  451 + that.changeFood(formdata)
  452 + }else{
  453 + that.addFood(formdata)
461 } 454 }
462 - }); 455 + })
463 }else{ 456 }else{
464 if(that.data.id){ 457 if(that.data.id){
465 that.changeFood(formdata) 458 that.changeFood(formdata)
@@ -139,6 +139,9 @@ export default { @@ -139,6 +139,9 @@ export default {
139 'App.Seller.BatchAddUser':null, 139 'App.Seller.BatchAddUser':null,
140 140
141 //获取添加员工二维码 141 //获取添加员工二维码
142 - 'App.Seller.CreatebatchQrcode':null 142 + 'App.Seller.CreatebatchQrcode':null,
  143 +
  144 + //获取七牛上传token信息
  145 + 'App.Qiniu.GetUploadToken':null,
143 146
144 } 147 }
  1 +;
  2 +(function (root, factory) {
  3 + if (typeof exports === "object") {
  4 + // CommonJS
  5 + module.exports = exports = factory();
  6 + } else if (typeof define === "function" && define.amd) {
  7 + // AMD
  8 + define([], factory);
  9 + } else {
  10 + // Global (browser)
  11 + root.CryptoJS = factory();
  12 + }
  13 +}(this, function () {
  14 +
  15 + /**
  16 + * CryptoJS core components.
  17 + */
  18 + var CryptoJS = CryptoJS || (function (Math, undefined) {
  19 + /*
  20 + * Local polyfil of Object.create
  21 + */
  22 + var create = Object.create || (function () {
  23 + function F() {};
  24 +
  25 + return function (obj) {
  26 + var subtype;
  27 +
  28 + F.prototype = obj;
  29 +
  30 + subtype = new F();
  31 +
  32 + F.prototype = null;
  33 +
  34 + return subtype;
  35 + };
  36 + }())
  37 +
  38 + /**
  39 + * CryptoJS namespace.
  40 + */
  41 + var C = {};
  42 +
  43 + /**
  44 + * Library namespace.
  45 + */
  46 + var C_lib = C.lib = {};
  47 +
  48 + /**
  49 + * Base object for prototypal inheritance.
  50 + */
  51 + var Base = C_lib.Base = (function () {
  52 +
  53 +
  54 + return {
  55 + /**
  56 + * Creates a new object that inherits from this object.
  57 + *
  58 + * @param {Object} overrides Properties to copy into the new object.
  59 + *
  60 + * @return {Object} The new object.
  61 + *
  62 + * @static
  63 + *
  64 + * @example
  65 + *
  66 + * var MyType = CryptoJS.lib.Base.extend({
  67 + * field: 'value',
  68 + *
  69 + * method: function () {
  70 + * }
  71 + * });
  72 + */
  73 + extend: function (overrides) {
  74 + // Spawn
  75 + var subtype = create(this);
  76 +
  77 + // Augment
  78 + if (overrides) {
  79 + subtype.mixIn(overrides);
  80 + }
  81 +
  82 + // Create default initializer
  83 + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  84 + subtype.init = function () {
  85 + subtype.$super.init.apply(this, arguments);
  86 + };
  87 + }
  88 +
  89 + // Initializer's prototype is the subtype object
  90 + subtype.init.prototype = subtype;
  91 +
  92 + // Reference supertype
  93 + subtype.$super = this;
  94 +
  95 + return subtype;
  96 + },
  97 +
  98 + /**
  99 + * Extends this object and runs the init method.
  100 + * Arguments to create() will be passed to init().
  101 + *
  102 + * @return {Object} The new object.
  103 + *
  104 + * @static
  105 + *
  106 + * @example
  107 + *
  108 + * var instance = MyType.create();
  109 + */
  110 + create: function () {
  111 + var instance = this.extend();
  112 + instance.init.apply(instance, arguments);
  113 +
  114 + return instance;
  115 + },
  116 +
  117 + /**
  118 + * Initializes a newly created object.
  119 + * Override this method to add some logic when your objects are created.
  120 + *
  121 + * @example
  122 + *
  123 + * var MyType = CryptoJS.lib.Base.extend({
  124 + * init: function () {
  125 + * // ...
  126 + * }
  127 + * });
  128 + */
  129 + init: function () {},
  130 +
  131 + /**
  132 + * Copies properties into this object.
  133 + *
  134 + * @param {Object} properties The properties to mix in.
  135 + *
  136 + * @example
  137 + *
  138 + * MyType.mixIn({
  139 + * field: 'value'
  140 + * });
  141 + */
  142 + mixIn: function (properties) {
  143 + for (var propertyName in properties) {
  144 + if (properties.hasOwnProperty(propertyName)) {
  145 + this[propertyName] = properties[propertyName];
  146 + }
  147 + }
  148 +
  149 + // IE won't copy toString using the loop above
  150 + if (properties.hasOwnProperty('toString')) {
  151 + this.toString = properties.toString;
  152 + }
  153 + },
  154 +
  155 + /**
  156 + * Creates a copy of this object.
  157 + *
  158 + * @return {Object} The clone.
  159 + *
  160 + * @example
  161 + *
  162 + * var clone = instance.clone();
  163 + */
  164 + clone: function () {
  165 + return this.init.prototype.extend(this);
  166 + }
  167 + };
  168 + }());
  169 +
  170 + /**
  171 + * An array of 32-bit words.
  172 + *
  173 + * @property {Array} words The array of 32-bit words.
  174 + * @property {number} sigBytes The number of significant bytes in this word array.
  175 + */
  176 + var WordArray = C_lib.WordArray = Base.extend({
  177 + /**
  178 + * Initializes a newly created word array.
  179 + *
  180 + * @param {Array} words (Optional) An array of 32-bit words.
  181 + * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  182 + *
  183 + * @example
  184 + *
  185 + * var wordArray = CryptoJS.lib.WordArray.create();
  186 + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  187 + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  188 + */
  189 + init: function (words, sigBytes) {
  190 + words = this.words = words || [];
  191 +
  192 + if (sigBytes != undefined) {
  193 + this.sigBytes = sigBytes;
  194 + } else {
  195 + this.sigBytes = words.length * 4;
  196 + }
  197 + },
  198 +
  199 + /**
  200 + * Converts this word array to a string.
  201 + *
  202 + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  203 + *
  204 + * @return {string} The stringified word array.
  205 + *
  206 + * @example
  207 + *
  208 + * var string = wordArray + '';
  209 + * var string = wordArray.toString();
  210 + * var string = wordArray.toString(CryptoJS.enc.Utf8);
  211 + */
  212 + toString: function (encoder) {
  213 + return (encoder || Hex).stringify(this);
  214 + },
  215 +
  216 + /**
  217 + * Concatenates a word array to this word array.
  218 + *
  219 + * @param {WordArray} wordArray The word array to append.
  220 + *
  221 + * @return {WordArray} This word array.
  222 + *
  223 + * @example
  224 + *
  225 + * wordArray1.concat(wordArray2);
  226 + */
  227 + concat: function (wordArray) {
  228 + // Shortcuts
  229 + var thisWords = this.words;
  230 + var thatWords = wordArray.words;
  231 + var thisSigBytes = this.sigBytes;
  232 + var thatSigBytes = wordArray.sigBytes;
  233 +
  234 + // Clamp excess bits
  235 + this.clamp();
  236 +
  237 + // Concat
  238 + if (thisSigBytes % 4) {
  239 + // Copy one byte at a time
  240 + for (var i = 0; i < thatSigBytes; i++) {
  241 + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  242 + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  243 + }
  244 + } else {
  245 + // Copy one word at a time
  246 + for (var i = 0; i < thatSigBytes; i += 4) {
  247 + thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  248 + }
  249 + }
  250 + this.sigBytes += thatSigBytes;
  251 +
  252 + // Chainable
  253 + return this;
  254 + },
  255 +
  256 + /**
  257 + * Removes insignificant bits.
  258 + *
  259 + * @example
  260 + *
  261 + * wordArray.clamp();
  262 + */
  263 + clamp: function () {
  264 + // Shortcuts
  265 + var words = this.words;
  266 + var sigBytes = this.sigBytes;
  267 +
  268 + // Clamp
  269 + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  270 + words.length = Math.ceil(sigBytes / 4);
  271 + },
  272 +
  273 + /**
  274 + * Creates a copy of this word array.
  275 + *
  276 + * @return {WordArray} The clone.
  277 + *
  278 + * @example
  279 + *
  280 + * var clone = wordArray.clone();
  281 + */
  282 + clone: function () {
  283 + var clone = Base.clone.call(this);
  284 + clone.words = this.words.slice(0);
  285 +
  286 + return clone;
  287 + },
  288 +
  289 + /**
  290 + * Creates a word array filled with random bytes.
  291 + *
  292 + * @param {number} nBytes The number of random bytes to generate.
  293 + *
  294 + * @return {WordArray} The random word array.
  295 + *
  296 + * @static
  297 + *
  298 + * @example
  299 + *
  300 + * var wordArray = CryptoJS.lib.WordArray.random(16);
  301 + */
  302 + random: function (nBytes) {
  303 + var words = [];
  304 +
  305 + var r = (function (m_w) {
  306 + var m_w = m_w;
  307 + var m_z = 0x3ade68b1;
  308 + var mask = 0xffffffff;
  309 +
  310 + return function () {
  311 + m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  312 + m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  313 + var result = ((m_z << 0x10) + m_w) & mask;
  314 + result /= 0x100000000;
  315 + result += 0.5;
  316 + return result * (Math.random() > .5 ? 1 : -1);
  317 + }
  318 + });
  319 +
  320 + for (var i = 0, rcache; i < nBytes; i += 4) {
  321 + var _r = r((rcache || Math.random()) * 0x100000000);
  322 +
  323 + rcache = _r() * 0x3ade67b7;
  324 + words.push((_r() * 0x100000000) | 0);
  325 + }
  326 +
  327 + return new WordArray.init(words, nBytes);
  328 + }
  329 + });
  330 +
  331 + /**
  332 + * Encoder namespace.
  333 + */
  334 + var C_enc = C.enc = {};
  335 +
  336 + /**
  337 + * Hex encoding strategy.
  338 + */
  339 + var Hex = C_enc.Hex = {
  340 + /**
  341 + * Converts a word array to a hex string.
  342 + *
  343 + * @param {WordArray} wordArray The word array.
  344 + *
  345 + * @return {string} The hex string.
  346 + *
  347 + * @static
  348 + *
  349 + * @example
  350 + *
  351 + * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  352 + */
  353 + stringify: function (wordArray) {
  354 + // Shortcuts
  355 + var words = wordArray.words;
  356 + var sigBytes = wordArray.sigBytes;
  357 +
  358 + // Convert
  359 + var hexChars = [];
  360 + for (var i = 0; i < sigBytes; i++) {
  361 + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  362 + hexChars.push((bite >>> 4).toString(16));
  363 + hexChars.push((bite & 0x0f).toString(16));
  364 + }
  365 +
  366 + return hexChars.join('');
  367 + },
  368 +
  369 + /**
  370 + * Converts a hex string to a word array.
  371 + *
  372 + * @param {string} hexStr The hex string.
  373 + *
  374 + * @return {WordArray} The word array.
  375 + *
  376 + * @static
  377 + *
  378 + * @example
  379 + *
  380 + * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  381 + */
  382 + parse: function (hexStr) {
  383 + // Shortcut
  384 + var hexStrLength = hexStr.length;
  385 +
  386 + // Convert
  387 + var words = [];
  388 + for (var i = 0; i < hexStrLength; i += 2) {
  389 + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  390 + }
  391 +
  392 + return new WordArray.init(words, hexStrLength / 2);
  393 + }
  394 + };
  395 +
  396 + /**
  397 + * Latin1 encoding strategy.
  398 + */
  399 + var Latin1 = C_enc.Latin1 = {
  400 + /**
  401 + * Converts a word array to a Latin1 string.
  402 + *
  403 + * @param {WordArray} wordArray The word array.
  404 + *
  405 + * @return {string} The Latin1 string.
  406 + *
  407 + * @static
  408 + *
  409 + * @example
  410 + *
  411 + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  412 + */
  413 + stringify: function (wordArray) {
  414 + // Shortcuts
  415 + var words = wordArray.words;
  416 + var sigBytes = wordArray.sigBytes;
  417 +
  418 + // Convert
  419 + var latin1Chars = [];
  420 + for (var i = 0; i < sigBytes; i++) {
  421 + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  422 + latin1Chars.push(String.fromCharCode(bite));
  423 + }
  424 +
  425 + return latin1Chars.join('');
  426 + },
  427 +
  428 + /**
  429 + * Converts a Latin1 string to a word array.
  430 + *
  431 + * @param {string} latin1Str The Latin1 string.
  432 + *
  433 + * @return {WordArray} The word array.
  434 + *
  435 + * @static
  436 + *
  437 + * @example
  438 + *
  439 + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  440 + */
  441 + parse: function (latin1Str) {
  442 + // Shortcut
  443 + var latin1StrLength = latin1Str.length;
  444 +
  445 + // Convert
  446 + var words = [];
  447 + for (var i = 0; i < latin1StrLength; i++) {
  448 + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  449 + }
  450 +
  451 + return new WordArray.init(words, latin1StrLength);
  452 + }
  453 + };
  454 +
  455 + /**
  456 + * UTF-8 encoding strategy.
  457 + */
  458 + var Utf8 = C_enc.Utf8 = {
  459 + /**
  460 + * Converts a word array to a UTF-8 string.
  461 + *
  462 + * @param {WordArray} wordArray The word array.
  463 + *
  464 + * @return {string} The UTF-8 string.
  465 + *
  466 + * @static
  467 + *
  468 + * @example
  469 + *
  470 + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  471 + */
  472 + stringify: function (wordArray) {
  473 + try {
  474 + return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  475 + } catch (e) {
  476 + throw new Error('Malformed UTF-8 data');
  477 + }
  478 + },
  479 +
  480 + /**
  481 + * Converts a UTF-8 string to a word array.
  482 + *
  483 + * @param {string} utf8Str The UTF-8 string.
  484 + *
  485 + * @return {WordArray} The word array.
  486 + *
  487 + * @static
  488 + *
  489 + * @example
  490 + *
  491 + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  492 + */
  493 + parse: function (utf8Str) {
  494 + return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  495 + }
  496 + };
  497 +
  498 + /**
  499 + * Abstract buffered block algorithm template.
  500 + *
  501 + * The property blockSize must be implemented in a concrete subtype.
  502 + *
  503 + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  504 + */
  505 + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  506 + /**
  507 + * Resets this block algorithm's data buffer to its initial state.
  508 + *
  509 + * @example
  510 + *
  511 + * bufferedBlockAlgorithm.reset();
  512 + */
  513 + reset: function () {
  514 + // Initial values
  515 + this._data = new WordArray.init();
  516 + this._nDataBytes = 0;
  517 + },
  518 +
  519 + /**
  520 + * Adds new data to this block algorithm's buffer.
  521 + *
  522 + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  523 + *
  524 + * @example
  525 + *
  526 + * bufferedBlockAlgorithm._append('data');
  527 + * bufferedBlockAlgorithm._append(wordArray);
  528 + */
  529 + _append: function (data) {
  530 + // Convert string to WordArray, else assume WordArray already
  531 + if (typeof data == 'string') {
  532 + data = Utf8.parse(data);
  533 + }
  534 +
  535 + // Append
  536 + this._data.concat(data);
  537 + this._nDataBytes += data.sigBytes;
  538 + },
  539 +
  540 + /**
  541 + * Processes available data blocks.
  542 + *
  543 + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  544 + *
  545 + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  546 + *
  547 + * @return {WordArray} The processed data.
  548 + *
  549 + * @example
  550 + *
  551 + * var processedData = bufferedBlockAlgorithm._process();
  552 + * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  553 + */
  554 + _process: function (doFlush) {
  555 + // Shortcuts
  556 + var data = this._data;
  557 + var dataWords = data.words;
  558 + var dataSigBytes = data.sigBytes;
  559 + var blockSize = this.blockSize;
  560 + var blockSizeBytes = blockSize * 4;
  561 +
  562 + // Count blocks ready
  563 + var nBlocksReady = dataSigBytes / blockSizeBytes;
  564 + if (doFlush) {
  565 + // Round up to include partial blocks
  566 + nBlocksReady = Math.ceil(nBlocksReady);
  567 + } else {
  568 + // Round down to include only full blocks,
  569 + // less the number of blocks that must remain in the buffer
  570 + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  571 + }
  572 +
  573 + // Count words ready
  574 + var nWordsReady = nBlocksReady * blockSize;
  575 +
  576 + // Count bytes ready
  577 + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  578 +
  579 + // Process blocks
  580 + if (nWordsReady) {
  581 + for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  582 + // Perform concrete-algorithm logic
  583 + this._doProcessBlock(dataWords, offset);
  584 + }
  585 +
  586 + // Remove processed words
  587 + var processedWords = dataWords.splice(0, nWordsReady);
  588 + data.sigBytes -= nBytesReady;
  589 + }
  590 +
  591 + // Return processed words
  592 + return new WordArray.init(processedWords, nBytesReady);
  593 + },
  594 +
  595 + /**
  596 + * Creates a copy of this object.
  597 + *
  598 + * @return {Object} The clone.
  599 + *
  600 + * @example
  601 + *
  602 + * var clone = bufferedBlockAlgorithm.clone();
  603 + */
  604 + clone: function () {
  605 + var clone = Base.clone.call(this);
  606 + clone._data = this._data.clone();
  607 +
  608 + return clone;
  609 + },
  610 +
  611 + _minBufferSize: 0
  612 + });
  613 +
  614 + /**
  615 + * Abstract hasher template.
  616 + *
  617 + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  618 + */
  619 + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  620 + /**
  621 + * Configuration options.
  622 + */
  623 + cfg: Base.extend(),
  624 +
  625 + /**
  626 + * Initializes a newly created hasher.
  627 + *
  628 + * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  629 + *
  630 + * @example
  631 + *
  632 + * var hasher = CryptoJS.algo.SHA256.create();
  633 + */
  634 + init: function (cfg) {
  635 + // Apply config defaults
  636 + this.cfg = this.cfg.extend(cfg);
  637 +
  638 + // Set initial values
  639 + this.reset();
  640 + },
  641 +
  642 + /**
  643 + * Resets this hasher to its initial state.
  644 + *
  645 + * @example
  646 + *
  647 + * hasher.reset();
  648 + */
  649 + reset: function () {
  650 + // Reset data buffer
  651 + BufferedBlockAlgorithm.reset.call(this);
  652 +
  653 + // Perform concrete-hasher logic
  654 + this._doReset();
  655 + },
  656 +
  657 + /**
  658 + * Updates this hasher with a message.
  659 + *
  660 + * @param {WordArray|string} messageUpdate The message to append.
  661 + *
  662 + * @return {Hasher} This hasher.
  663 + *
  664 + * @example
  665 + *
  666 + * hasher.update('message');
  667 + * hasher.update(wordArray);
  668 + */
  669 + update: function (messageUpdate) {
  670 + // Append
  671 + this._append(messageUpdate);
  672 +
  673 + // Update the hash
  674 + this._process();
  675 +
  676 + // Chainable
  677 + return this;
  678 + },
  679 +
  680 + /**
  681 + * Finalizes the hash computation.
  682 + * Note that the finalize operation is effectively a destructive, read-once operation.
  683 + *
  684 + * @param {WordArray|string} messageUpdate (Optional) A final message update.
  685 + *
  686 + * @return {WordArray} The hash.
  687 + *
  688 + * @example
  689 + *
  690 + * var hash = hasher.finalize();
  691 + * var hash = hasher.finalize('message');
  692 + * var hash = hasher.finalize(wordArray);
  693 + */
  694 + finalize: function (messageUpdate) {
  695 + // Final message update
  696 + if (messageUpdate) {
  697 + this._append(messageUpdate);
  698 + }
  699 +
  700 + // Perform concrete-hasher logic
  701 + var hash = this._doFinalize();
  702 +
  703 + return hash;
  704 + },
  705 +
  706 + blockSize: 512 / 32,
  707 +
  708 + /**
  709 + * Creates a shortcut function to a hasher's object interface.
  710 + *
  711 + * @param {Hasher} hasher The hasher to create a helper for.
  712 + *
  713 + * @return {Function} The shortcut function.
  714 + *
  715 + * @static
  716 + *
  717 + * @example
  718 + *
  719 + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  720 + */
  721 + _createHelper: function (hasher) {
  722 + return function (message, cfg) {
  723 + return new hasher.init(cfg).finalize(message);
  724 + };
  725 + },
  726 +
  727 + /**
  728 + * Creates a shortcut function to the HMAC's object interface.
  729 + *
  730 + * @param {Hasher} hasher The hasher to use in this HMAC helper.
  731 + *
  732 + * @return {Function} The shortcut function.
  733 + *
  734 + * @static
  735 + *
  736 + * @example
  737 + *
  738 + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  739 + */
  740 + _createHmacHelper: function (hasher) {
  741 + return function (message, key) {
  742 + return new C_algo.HMAC.init(hasher, key).finalize(message);
  743 + };
  744 + }
  745 + });
  746 +
  747 + /**
  748 + * Algorithm namespace.
  749 + */
  750 + var C_algo = C.algo = {};
  751 +
  752 + return C;
  753 + }(Math));
  754 +
  755 +
  756 + return CryptoJS;
  757 +
  758 +}));
  1 +(function () {
  2 + var config = {
  3 + qiniuRegion: '',
  4 + qiniuImageURLPrefix: '',
  5 + qiniuUploadToken: '',
  6 + qiniuUploadTokenURL: '',
  7 + qiniuUploadTokenFunction: null,
  8 + qiniuShouldUseQiniuFileName: false
  9 + }
  10 +
  11 + module.exports = {
  12 + init: init,
  13 + upload: upload,
  14 + }
  15 +
  16 + // 在整个程序生命周期中,只需要 init 一次即可
  17 + // 如果需要变更参数,再调用 init 即可
  18 + function init(options) {
  19 + config = {
  20 + qiniuRegion: '',
  21 + qiniuImageURLPrefix: '',
  22 + qiniuUploadToken: '',
  23 + qiniuUploadTokenURL: '',
  24 + qiniuUploadTokenFunction: null,
  25 + qiniuShouldUseQiniuFileName: false
  26 + };
  27 + updateConfigWithOptions(options);
  28 + }
  29 +
  30 + function updateConfigWithOptions(options) {
  31 + if (options.region) {
  32 + config.qiniuRegion = options.region;
  33 + } else {
  34 + console.error('qiniu uploader need your bucket region');
  35 + }
  36 + if (options.uptoken) {
  37 + config.qiniuUploadToken = options.uptoken;
  38 + } else if (options.uptokenURL) {
  39 + config.qiniuUploadTokenURL = options.uptokenURL;
  40 + } else if (options.uptokenFunc) {
  41 + config.qiniuUploadTokenFunction = options.uptokenFunc;
  42 + }
  43 + if (options.domain) {
  44 + config.qiniuImageURLPrefix = options.domain;
  45 + }
  46 + config.qiniuShouldUseQiniuFileName = options.shouldUseQiniuFileName
  47 + }
  48 +
  49 + function upload(filePath, success, fail, options, progress, cancelTask, before, complete) {
  50 + if (null == filePath) {
  51 + console.error('qiniu uploader need filePath to upload');
  52 + return;
  53 + }
  54 + if (options) {
  55 + updateConfigWithOptions(options);
  56 + }
  57 + if (config.qiniuUploadToken) {
  58 + doUpload(filePath, success, fail, options, progress, cancelTask, before, complete);
  59 + } else if (config.qiniuUploadTokenURL) {
  60 + getQiniuToken(function () {
  61 + doUpload(filePath, success, fail, options, progress, cancelTask, before, complete);
  62 + });
  63 + } else if (config.qiniuUploadTokenFunction) {
  64 + config.qiniuUploadToken = config.qiniuUploadTokenFunction();
  65 + if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) {
  66 + console.error('qiniu UploadTokenFunction result is null, please check the return value');
  67 + return
  68 + }
  69 + doUpload(filePath, success, fail, options, progress, cancelTask, before, complete);
  70 + } else {
  71 + console.error('qiniu uploader need one of [uptoken, uptokenURL, uptokenFunc]');
  72 + return;
  73 + }
  74 + }
  75 +
  76 + function doUpload(filePath, success, fail, options, progress, cancelTask, before, complete) {
  77 + if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) {
  78 + console.error('qiniu UploadToken is null, please check the init config or networking');
  79 + return
  80 + }
  81 + var url = uploadURLFromRegionCode(config.qiniuRegion);
  82 + console.log('filePathfilePathfilePath', filePath);
  83 + var fileName = filePath[0].split('//')[1];
  84 + if (options && options.key) {
  85 + fileName = options.key;
  86 + }
  87 + var formData = {
  88 + 'token': config.qiniuUploadToken
  89 + };
  90 + if (!config.qiniuShouldUseQiniuFileName) {
  91 + formData['key'] = fileName
  92 + }
  93 + before && before();
  94 + var uploadTask = wx.uploadFile({
  95 + url: url,
  96 + filePath: filePath,
  97 + name: 'file',
  98 + formData: formData,
  99 + success: function (res) {
  100 + var dataString = res.data
  101 + // // this if case is a compatibility with wechat server returned a charcode, but was fixed
  102 + // if(res.data.hasOwnProperty('type') && res.data.type === 'Buffer'){
  103 + // dataString = String.fromCharCode.apply(null, res.data.data)
  104 + // }
  105 + try {
  106 + var dataObject = JSON.parse(dataString);
  107 + //do something
  108 + var fileUrl = config.qiniuImageURLPrefix + '/' + dataObject.key;
  109 + dataObject.fileUrl = fileUrl
  110 + dataObject.imageURL = fileUrl;
  111 + // console.log(dataObject);
  112 + if (success) {
  113 + success(dataObject);
  114 + }
  115 + } catch (e) {
  116 + console.log('parse JSON failed, origin String is: ' + dataString)
  117 + if (fail) {
  118 + fail(e);
  119 + }
  120 + }
  121 + },
  122 + fail: function (error) {
  123 + console.error(error);
  124 + if (fail) {
  125 + fail(error);
  126 + }
  127 + },
  128 + complete: function (err) {
  129 + complete && complete(err);
  130 + }
  131 + })
  132 +
  133 + uploadTask.onProgressUpdate((res) => {
  134 + progress && progress(res)
  135 + })
  136 +
  137 + cancelTask && cancelTask(() => {
  138 + uploadTask.abort()
  139 + })
  140 + }
  141 +
  142 + function getQiniuToken(callback) {
  143 + console.log('urlurl', config.qiniuUploadTokenURL);
  144 + wx.request({
  145 + url: config.qiniuUploadTokenURL,
  146 + header: {
  147 + 'Content-Type': "application/json",
  148 + // 'Cookie': 'vertx-web.session=' + wx.getStorageSync("sessionId")
  149 + },
  150 + success: function (res) {
  151 + var token = res.data.message;
  152 + if (token && token.length > 0) {
  153 + config.qiniuUploadToken = token;
  154 + if (callback) {
  155 + callback();
  156 + }
  157 + } else {
  158 + console.error('qiniuUploader cannot get your token, please check the uptokenURL or server')
  159 + }
  160 + },
  161 + fail: function (error) {
  162 + console.error('qiniu UploadToken is null, please check the init config or networking: ' + error);
  163 + }
  164 + })
  165 + }
  166 +
  167 + function uploadURLFromRegionCode(code) {
  168 + var uploadURL = null;
  169 + switch (code) {
  170 + case 'ECN':
  171 + uploadURL = 'https://up.qiniup.com';
  172 + break;
  173 + case 'NCN':
  174 + uploadURL = 'https://up-z1.qiniup.com';
  175 + break;
  176 + case 'z2':
  177 + uploadURL = 'https://up-z0.qiniup.com';
  178 + break;
  179 + case 'NA':
  180 + uploadURL = 'https://up-na0.qiniup.com';
  181 + break;
  182 + case 'ASG':
  183 + uploadURL = 'https://up-as0.qiniup.com';
  184 + break;
  185 + default:
  186 + console.error('please make the region is with one of [ECN, SCN, NCN, NA, ASG]');
  187 + }
  188 + return uploadURL;
  189 + }
  190 +
  191 +})();
1 var uri=require('uri.js') 1 var uri=require('uri.js')
  2 +import qiniuUploader from "./upload/qiniuUploader";
2 3
3 4
4 5
@@ -185,11 +186,36 @@ function orderPay(charge){ @@ -185,11 +186,36 @@ function orderPay(charge){
185 } 186 }
186 }) 187 })
187 } 188 }
  189 +// 上传图片
  190 +function uploadFile(imgArr, token,type){
  191 + let path = imgArr.split('//')[1]
  192 + let promisevariable = new Promise(function (resolve, reject) {
  193 + qiniuUploader.upload(
  194 + imgArr, //上传的图片
  195 + (res) => { //回调 success
  196 + console.log(res, '七牛云返回')
  197 + resolve(res.imageURL)
  198 + }, (error) => { //回调 fail
  199 + reject('error');
  200 + },
  201 + { // 参数设置 地区代码 token domain 和直传的链接 注意七牛四个不同地域的链接不一样,我使用的是华南地区
  202 + uptokenURL: token,
  203 + uploadURL: 'http://nosqn.colorcun.com',
  204 + region: 'ECN', //服务器区域号
  205 + domain: 'http://nosqn.colorcun.com',//七牛云域名
  206 + key: `pinglun/${type}/${path}`, // 上传到七牛云图片就是这路径
  207 + uptoken: token,
  208 + uptokeFunc:'',
  209 + })
  210 + })
  211 + return promisevariable;
  212 +}
188 module.exports = { 213 module.exports = {
189 formatTime: formatTime, 214 formatTime: formatTime,
190 unixtoTime:unixtoTime, 215 unixtoTime:unixtoTime,
191 timetouUnix:timetouUnix, 216 timetouUnix:timetouUnix,
192 orderPay:orderPay, 217 orderPay:orderPay,
  218 + uploadFile,
193 cgi:function(act){ 219 cgi:function(act){
194 return uri.HOST__LINE+act //正式 220 return uri.HOST__LINE+act //正式
195 //return uri.HOST__TEST+act //测试 221 //return uri.HOST__TEST+act //测试