12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import config from './config.js';
- import store from '@/store/store.js';
- const visit = function(params) {
- if (!params) params = new Object;
- params.app_id = config.appId;
- params.device = config.dev;
- let url = config.apiUrl + 'miniapp/visit'; //仅仅请求 不响应服务器的操作
- uni.request({
- url: url,
- data: params,
- method: 'POST',
- success() {
- console.log('日志写入成功');
- },
- fail() {
- console.log('日志写入失败');
- },
- });
- }
- const post = function(url, params) {
- if (!params) params = new Object;
- params.device = config.dev;
- params.app_id = config.appId;
- return new Promise((resolve, reject) => {
- uni.request({
- url: config.apiUrl + url, //仅为示例,并非真实接口地址。
- data: params,
- method: 'POST',
- success: (res) => {
- uni.hideLoading();
- if (res.statusCode == 200) {
- if (res.data.code == 200) {
- if (res.data.code == 100) { //未登录的情况
- store.commit('setMember', null);
- uni.removeStorageSync('member-token');
- reject({
- code: res.data.code,
- msg: res.data.msg
- });
- } else {
- resolve(res.data.data);
- }
- } else {
- uni.showToast({
- icon: 'none',
- title: res.data.msg + '#' + res.data.code
- });
- reject({
- code: res.data.code,
- msg: res.data.msg
- });
- }
- } else {
- uni.showToast({
- icon: 'none',
- title: "网络异常"
- });
- reject({
- code: 500,
- msg: '网络异常'
- });
- }
- },
- fail: (res) => {
- uni.hideLoading();
- uni.showToast({
- icon: 'none',
- title: "服务器繁忙"
- });
- reject({
- code: 500,
- msg: '服务器繁忙'
- });
- }
- });
- });
- }
- //需要登录的使用这个
- const api = function(url, params) {
- if (!params) params = new Object;
- let token = uni.getStorageSync('member-token');
- params.token = token;
- return this.post(url, params);
- }
- export default {
- post,
- api,
- visit
- }
|