download.js

fetch('http://api-alpha.heywoof.com/order/waybills/v2/shipping-report', {
    method: "POST",
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        "header": {"authToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NjYyMDA1NjQsInVzZXJJZCI6IjI4ODk4ODM3MDM1OTU0OTk1MiIsImNoYW5uZWxJZCI6MTF9.QE24ZiwMn3NbpH6M6g_6WV2WLQcDdohnaYcJyuJ6_nI"},
        "data": {}
    })
}).then(function(response) {
    return response.blob();
}).then(function(blob) {
    let url = window.URL.createObjectURL(blob);

    let a = document.createElement("a");
    document.body.appendChild(a);
    a.style = "display: none";
    a.href = url;
    a.download = "发货报表.xlsx";
    a.click();
    window.URL.revokeObjectURL(url);
});

参考:

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

6,814 total views, 1 views today

LeetCode: Two Sum & Add Two Numbers

周末没事,刷一下 LeetCode。

Two Sum

JavaScript

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(nums, target) {
    for(i in nums) {
        for (j in nums) {
            if (i < j && nums[i] + nums[j] == target) {
                return [Number(i), Number(j)];
            }
        }
    }
};

Python 3

class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        dict = {}
        
        for i, v in enumerate(nums):
            if target - v in dict:
                return [dict[target - v], i]
            dict[v] = i

Add Two Numbers

JavaScript

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var addTwoNumbers = function(l1, l2) {
    
    sum = l3 = new ListNode(0);
    
    while (l1 || l2) {
        if (l1) {
            l3.val += l1.val;
            l1 = l1.next;
        }
        
        if (l2) {
            l3.val += l2.val;
            l2 = l2.next;
        }
        
        if (l3.val >= 10) {
            l3.val -= 10;
            l3.next = new ListNode(1);
            l3 = l3.next;
        } else if (l1 || l2) {
            l3.next = new ListNode(0);
            l3 = l3.next;
        } 
    }
    
    return sum;
};

Python3

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        add = l3 = ListNode(0)
    
        while l1 or l2:
            if l1:
                l3.val += l1.val
                l1 = l1.next

            if l2:
                l3.val += l2.val
                l2 = l2.next

            if l3.val >= 10:
                l3.val -= 10
                l3.next = ListNode(1)
                l3 = l3.next
            elif l1 or l2:
                l3.next = ListNode(0)
                l3 = l3.next
    
        return add

426 total views, 3 views today