提交说明

main
RIceWqy 2 years ago
parent 63906928f0
commit 2f66303367

@ -340,7 +340,7 @@
/**
* 登录提示页
*/
import jsonrpc from "@/shopro/jsonrpc/jsonrpc2.0.js"
import FormValidate from "@/shopro/validate/form";
import schema from "@/uview-ui/libs/util/async-validator";
import wechat from "@/shopro/wechat/wechat";
@ -505,17 +505,7 @@ export default {
//
validation(key, callback = () => { }) {
console.log("validation")
let wqy = function(responce){
console.log(responce)
}
let res = {
"method":"/account/login",
"jsonrpc":"2.0",
"params":{"username":"admin",
"password":"123"}
}
jsonrpc.send("http://192.168.10.151:5080/jsonrpc",res,wqy,wqy)
let that = this;
//
let fieldValue = this.form[this.authType].data[key];

@ -7,7 +7,7 @@ import {
import store from "@/shopro/store";
import uView from "uview-ui";
import shopro from "@/shopro";
import jsonrpc from "@/shopro/request/indexJson.js"
async function bootstrap() {
App.mpType = "app";
@ -17,7 +17,7 @@ async function bootstrap() {
Vue.use(uView);
// 加载shopro
Vue.use(shopro);
Vue.use(jsonrpc)
const app = new Vue({
store,
...App

@ -21,6 +21,7 @@ import threeCatgory from './category/three-catgory.vue';
import twoCatgory from './category/two-catgory.vue';
import oneCatgory from './category/one-catgory.vue';
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
import jsonrpc from "@/shopro/jsonrpc/jsonrpc2.0.js"
export default {
components: {
takeoutCatgory,
@ -46,9 +47,19 @@ export default {
* type4:三级分类 type3:二级分类 ,type2:一级分类,type1:快速购买
*/
getCategory() {
this.$http('category.info', {
id: this.$Route.query.id ? this.$Route.query.id : 0
}).then(res => {
this.$jsonrpc('category.info',{id: this.$Route.query.id ? this.$Route.query.id : 0}).then(res =>{
if (res.result?.type) {
this.categoryType = Number(res.result.type);
this.categoryStyleId = Number(res.result.id);
uni.setNavigationBarTitle({
title: res.result?.name
});
}
})
/* this.$http('category.info', { id: this.$Route.query.id ? this.$Route.query.id : 0}).then(res => {
if (res.code === 1) {
if (res.data?.type) {
this.categoryType = Number(res.data.type);
@ -58,7 +69,7 @@ export default {
});
}
}
});
}); */
}
}
};

@ -79,6 +79,8 @@ export default {
methods: {
//
getCategory() {
console.log("getCategory111")
this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
@ -92,6 +94,7 @@ export default {
//
getGoodsList() {
console.log("getGoodsList")
let that = this;
that.$http('goods.lists', {
category_id: that.categoryID,
@ -108,6 +111,7 @@ export default {
//
loadMore() {
console.log("loadMore")
if (this.currentPage < this.lastPage) {
this.currentPage += 1;
this.getGoodsList();
@ -115,6 +119,7 @@ export default {
},
onType(index) {
console.log("onType")
this.listId = index;
this.categoryID = this.categoryData[index].id;
this.goodsList = [];
@ -123,6 +128,7 @@ export default {
},
//
jump(path, parmas) {
console.log("jump")
this.$Router.push({
path: path,
query: parmas

@ -196,6 +196,7 @@
//
async getCategory() {
console.log("getCategory222")
const tabbarData = await this.$http('category.detail', {
id: this.categoryStyleId
});

@ -68,13 +68,22 @@ export default {
},
methods: {
getCategory() {
this.$http('category.detail', {
console.log("getCategory222")
this.$jsonrpc('category.info', {
id: this.categoryStyleId
}).then(res => {
console.log("jsonrpc detail @@@",res)
this.categoryData = res.result.children;
});
/* this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
if (res.code === 1) {
this.categoryData = res.data.children;
}
});
}); */
},
onType(id) {
this.listId = id;

@ -76,13 +76,21 @@ export default {
},
methods: {
getCategory() {
this.$http('category.detail', {
console.log("getCategory333")
this.$jsonrpc('category.detail', {
id: this.categoryStyleId
}).then(res => {
this.categoryData = res.result.children;
});
/* this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
if (res.code === 1) {
this.categoryData = res.data.children;
}
});
}); */
},
onType(id) {
this.listId = id;

@ -71,3 +71,5 @@ function getApiPath(url) {
});
return api;
}

@ -0,0 +1,82 @@
import Request from './request'
import apiList from './apis.js'
import store from '@/shopro/store/index.js'
const shoproRequest = new Request();
export default {
install(Vue) {
Vue.prototype.$jsonrpc = function (
url,
data = {},
toastBefore = '', // 请求前加载提示
toastAfter = true, // 请求后错误提示
) {
if (typeof url !== "string") {
return;
}
let api = getApiPath(url);
/* 请求之前拦截器 */
shoproRequest.interceptor.request((config, cancel) => {
let token = uni.getStorageSync('token');
if (api.auth && !token) {
store.dispatch('showAuthModal');
uni.hideLoading();
throw (`暂未登录,已阻止此次API请求: '${api.url}'`);
}
token && shoproRequest.setConfig(config => {
config.header.token = token;
});
if (toastBefore !== '') {
uni.showLoading({
title: toastBefore,
mask: true
});
}
return config;
});
/* 请求之后拦截器 */
shoproRequest.interceptor.response((response) => {
uni.hideLoading();
if (response.code === 0) {
if (toastAfter) {
uni.showToast({
title: response.msg || '请求出错,稍后重试',
icon: 'none',
duration: 1000,
mask: true
});
}
}
// token过期注销
if (response.code === 401) {
store.dispatch('logout');
store.dispatch('showAuthModal');
throw (`登录已过期或注销,已阻止此次API请求: '${api.url}'`);
}
return response;
});
return shoproRequest.requestJson({
url: api.url,
data,
method: api.method
});
}
}
};
// 组装接口路径
function getApiPath(url) {
let apiArray = url.split(".");
let api = apiList;
apiArray.forEach(v => {
api = api[v];
});
return api;
}

@ -91,25 +91,80 @@ export default class Request {
* @returns {Promise<unknown>}
*/
async request(options = {}) {
options = {
...options,
...this.config,
...this.requestBefore(options)
}
return new Promise((resolve, reject) => {
/* console.log("data",options.data)
let createJsonRpc ={
method: options.url
}
createJsonRpc.params ={
...options.data
}
options.url = "http://localhost:9001/jsonrpc"
options.data = createJsonRpc
options.method="POST"
console.log(createJsonRpc) */
let mergeUrl = Request.isUrl(options.url) ? options.url : (options.baseUrl + options.url)
if (JSON.stringify(options.params) !== '{}') {
let query = Request.addQueryString(options.params);
mergeUrl += mergeUrl.indexOf('?') === -1 ? `?${query}` : `&${query}`
}
options.url = mergeUrl
options.success = res => {
resolve(this.requestAfter(res.data))
}
options.fail = err => {
reject(this.requestAfter(err))
}
uni.request(options)
})
}
async requestJson(options = {}) {
options = {
...options,
...this.config,
...this.requestBefore(options)
}
return new Promise((resolve, reject) => {
let createJsonRpc ={
method: '/'+options.url
}
createJsonRpc.params ={
...options.data
}
options.url = "http://localhost:9001/jsonrpc"
options.data = createJsonRpc
options.method="POST"
console.log(createJsonRpc)
/* let mergeUrl = Request.isUrl(options.url) ? options.url : (options.baseUrl + options.url)
if (JSON.stringify(options.params) !== '{}') {
let query = Request.addQueryString(options.params);
mergeUrl += mergeUrl.indexOf('?') === -1 ? `?${query}` : `&${query}`
}
options.url = mergeUrl */
options.success = res => {
console.log(res,"res")
resolve(this.requestAfter(res.data))
}
options.fail = err => {
reject(this.requestAfter(err))
}
uni.request(options)
})
}

Loading…
Cancel
Save