Browse Source

add

添加agreement页面和优化request提示
master
wei 2 weeks ago
parent
commit
6111f3f81f
  1. 2
      .hbuilderx/launch.json
  2. 23
      libs/api/index.js
  3. 18
      libs/request/beforeRequest.js
  4. 30
      libs/request/index.js
  5. 6
      pages.json
  6. 26
      pages/agreement/agreement.vue
  7. 23
      pages/login/login.vue

2
.hbuilderx/launch.json

@ -6,7 +6,7 @@
"type" : "uni-app:app-android"
},
{
"playground" : "standard",
"playground" : "custom",
"type" : "uni-app:app-ios"
}
]

23
libs/api/index.js

@ -232,12 +232,12 @@ export function addHonestApi(data = {}) {
* @param {{code: string}} data
* @returns
*/
export function xcxWxLoginApi(data = {}, header) {
export function xcxWxLoginApi(data = {}) {
return request({
merrorMessage: "微信openid",
errorMessage: "微信openid",
method: "POST",
data,
header,
header: { "content-type": "application/x-www-form-urlencoded;charset=utf-8" },
url: "/thirdOauth/XcxWxLogin.do",
});
}
@ -248,9 +248,24 @@ export function xcxWxLoginApi(data = {}, header) {
*/
export function getUserByXcxAPPOpenIdApi(data) {
return request({
merrorMessage: "微信用户",
errorMessage: "微信用户",
method: "POST",
data,
url: "/user/getUserByXcxAPPOpenId.do",
});
}
/**
* 获取协议
* @param {*} data
* @returns
*/
export function getUserTreatyApi(data) {
return request({
errorMessage: "用户协议",
url: "userTreaty/getUserTreaty.do",
method: "GET",
data,
header: { "content-type": "application/x-www-form-urlencoded;charset=utf-8" },
});
}

18
libs/request/beforeRequest.js

@ -15,9 +15,18 @@ export async function beforeRequest(config) {
config.url += `?${stringifyQuery(config.params)}`;
}
// 处理请求头部
config.header = {
...config.header,
session: uni.getStorageSync("session") || "",
tenant_id: uni.getStorageSync("tenantId") || "10001",
// version: "2.0",
};
// 默认请求方式
if (!("method" in config))
config.method = "POST";
if (!("method" in config)) {
config.method = "GET";
}
// 处理基础路径
const base_url = BASE_URL;
@ -40,6 +49,11 @@ export async function beforeRequest(config) {
return config;
}
/**
* 处理请求参数将对象转换为查询字符串
* @param {object} obj
* @returns {string} 查询字符串
*/
function stringifyQuery(obj) {
return Object.keys(obj)
.map((key) => {

30
libs/request/index.js

@ -1,14 +1,32 @@
import { afterResponse } from "./afterResponse";
import { beforeRequest } from "./beforeRequest";
// * _base_url {boolean|string} 接口基础路径,默认true会自动设置为全局基础路径
// * _with_token {boolean} 是否挂载token,默认true
// * _return_origin{boolean} 是否返回原始数据(uni.request方法的原始值),默认false,若开启则 _service_fail 相关参数失效
// * _service_fail_toast {boolean} 是否在业务失败(响应code不为0)时自动Toast错误的msg,默认true
// * _service_fail_throw {boolean} 是否在业务失败(响应code不为0)时抛出业务失败异常,默认true。业务异常类可通过 error.is_service_fail_error 识别
/**
* @typedef {object} headerType
* @property {string} session - 会话标识uni.getStorageSync("session") || ""
* @property {string} tenant_id - 租户IDuni.getStorageSync("tenantId") || "10001"
* @property {string} version - 接口版本号"2.0"
*/
/**
* @typedef {object} configType
* @property {string} url - 接口路径
* @property {object} params - 自动序列化到url
* @property {string} errorMessage - 错误定位, 留空则不启用
* @property {string} method - 请求方法默认为 "GET"
* @property {headerType} header - 请求头
*/
/**
* 发起请求
* @param {object} config 基于uni.request的config参数除此之外拓展了一些参数
* _base_url {boolean|string} 接口基础路径默认true会自动设置为全局基础路径
* _with_token {boolean} 是否挂载token默认true
* _return_origin{boolean} 是否返回原始数据uni.request方法的原始值默认false若开启则 _service_fail 相关参数失效
* _service_fail_toast {boolean} 是否在业务失败响应code不为0时自动Toast错误的msg默认true
* _service_fail_throw {boolean} 是否在业务失败响应code不为0时抛出业务失败异常默认true业务异常类可通过 error.is_service_fail_error 识别
* @param {configType} config 基于uni.request的config参数除此之外拓展了一些参数
* @returns
*/
async function request(config) {
return uni.request(await beforeRequest(config)).then((response) => {

6
pages.json

@ -50,6 +50,12 @@
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/agreement/agreement",
"style": {
"navigationBarTitleText": ""
}
}
],
"tabBar": {

26
pages/agreement/agreement.vue

@ -0,0 +1,26 @@
<script setup>
import {
getCurrentInstance,
onMounted,
} from "vue";
// import { onLoad } from "@dcloudio/uni-app";
// onLoad((options) => {
// getOpenerEventChannel
// });
const content = ref("");
onMounted(() => {
const instance = getCurrentInstance().proxy;
const eventChannel = instance.getOpenerEventChannel();
eventChannel.emit("getContent", (data) => {
console.log(data, 333);
// content
});
});
</script>
<template>
<view>
agreement
</view>
</template>

23
pages/login/login.vue

@ -2,7 +2,7 @@
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref } from "vue";
import navigation from "@/components/navigation/navigation.vue";
import { getmyareaApi, getUserByXcxAPPOpenIdApi, xcxWxLoginApi } from "@/libs/api";
import { getmyareaApi, getUserByXcxAPPOpenIdApi, getUserTreatyApi, xcxWxLoginApi } from "@/libs/api";
let appData = getApp().globalData;
/**
@ -84,10 +84,7 @@ function onGetUserProfile() {
function wxLogin() {
uni.login({
async success(resp) {
const resp2 = await xcxWxLoginApi(
{ code: resp.code },
{ "content-type": "application/x-www-form-urlencoded;charset=utf-8" },
);
const resp2 = await xcxWxLoginApi({ code: resp.code });
if (resp2.code === "0") {
openid.value = resp2.openid;
uni.setStorageSync("openid", openid.value);
@ -156,7 +153,21 @@ function onBackHome() {
*/
function onForgetPassword() { }
function onOpenUserAgreement() { }
async function onOpenUserAgreement() {
const resp = await getUserTreatyApi();
console.log(resp, 2333);
if (resp.code === "0") {
uni.navigateTo({
url: "/pages/agreement/agreement",
events: {
async getContent(callback) {
callback(resp.data.serviceAgreement);
},
},
});
}
}
function onOpenPrivacyAgreement() { }
onLoad(() => {

Loading…
Cancel
Save