Skip to content

Commit

Permalink
feat: token携带更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaviilee committed Jan 5, 2025
1 parent 6e363b1 commit bda0dcf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jx3box/jx3box-comment-ui",
"version": "2.0.1",
"version": "2.0.2",
"scripts": {
"dev": "env DEV_SERVER=true vue-cli-service serve",
"serve": "vue-cli-service serve",
Expand All @@ -10,8 +10,8 @@
},
"main": "index.js",
"dependencies": {
"@jx3box/jx3box-common": "^8.2.18",
"@jx3box/jx3box-common-ui": "^8.7.0",
"@jx3box/jx3box-common": "^8.5.4",
"@jx3box/jx3box-common-ui": "^9.0.27",
"@jx3box/jx3box-emotion": "^1.2.8",
"core-js": "^3.6.4",
"csslab": "^4.0.4",
Expand Down Expand Up @@ -57,4 +57,4 @@
"engines": {
"node": ">= 14 < 17"
}
}
}
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<Comment id="80449" category="post" order="desc" :homework="true" />
<!-- <Comment id="80449" category="post" order="desc" :homework="true" /> -->
<!-- <Comment id="81964" category="post" order="desc" :homework="true" /> -->
<!-- <Comment :id="30015" category="post" order="desc" /> -->
<Comment :id="19382" category="post" order="desc" />
</template>

<script>
Expand Down
16 changes: 16 additions & 0 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { __Links, __next } from "@jx3box/jx3box-common/data/jx3box.json"
import { Notification } from "element-ui"
import { $pay } from "@jx3box/jx3box-common/js/https"

// 从url中获取参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
return r ? decodeURIComponent(r[2]) : null;
}


export const GET = function (url, queryParams) {
let options = {
Expand Down Expand Up @@ -95,6 +102,15 @@ function __fetch(url, queryParams, options) {
}
url = url + "?" + queryQueue.join("&")
}

// 设置认证头
let token = getUrlParam("__token");
token = token ? token : (localStorage && localStorage.getItem("token"));
if (token) {
const credentials = btoa(token + ':' + 'next common request');
options.headers["Authorization"] = "Basic " + credentials
}

return fetch(url, options).then((resp) => {
switch (resp.status) {
case 200:
Expand Down

0 comments on commit bda0dcf

Please sign in to comment.