guhongwei 2 years ago
parent
commit
94c270f212

+ 0 - 31
.eslintrc.js

@@ -1,31 +0,0 @@
-/*
- * Eslint config file
- * Documentation: https://eslint.org/docs/user-guide/configuring/
- * Install the Eslint extension before using this feature.
- */
-module.exports = {
-  env: {
-    es6: true,
-    browser: true,
-    node: true,
-  },
-  ecmaFeatures: {
-    modules: true,
-  },
-  parserOptions: {
-    ecmaVersion: 2018,
-    sourceType: 'module',
-  },
-  globals: {
-    wx: true,
-    App: true,
-    Page: true,
-    getCurrentPages: true,
-    getApp: true,
-    Component: true,
-    requirePlugin: true,
-    requireMiniProgram: true,
-  },
-  // extends: 'eslint:recommended',
-  rules: {},
-}

+ 8 - 4
app.js

@@ -1,10 +1,11 @@
-// app.js
+import * as httpUtil from "./utils/httpUtil";
+import $checkRes from './utils/checkRes';
 App({
     onLaunch() {
         // 登录
         wx.login({
             success: res => {
-                console.log(res);
+                // console.log(res);
             }
         })
         //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度
@@ -17,10 +18,13 @@ App({
         })
     },
     globalData: {
-        serverUrl: "https://broadcast.waityou24.cn",
+        serverUrl: "http://127.0.0.1:10102",
+        wechatUrl: 'https://broadcast.waityou24.cn',
         // 当前设备信息
         client: {},
         // 微信用户openid,sessionKey
         wxInfo: {},
-    }
+    },
+    ...httpUtil,
+    $checkRes
 })

+ 10 - 18
components/upload/index.js

@@ -9,32 +9,24 @@ Component({
     methods: {
         // 图片上传
         imgUpload() {
-
             const that = this;
             const name = that.data.name;
             wx.chooseImage({
                 count: 1,
                 sizeType: ['original', 'compressed'],
                 sourceType: ['album', 'camera'],
-                success(res) {
-                    const file = res.tempFilePaths;
-                    wx.uploadFile({
-                        url: `${app.globalData.serverUrl}/files/test/upload`,
-                        filePath: file[0],
-                        name: 'file',
-                        formData: {},
-                        success: (arr) => {
-                            let aee = JSON.parse(arr.data);
-                            if (arr.statusCode == 200) {
-                                that.triggerEvent('imgUpload', { data: { name: aee.name, url: `${app.globalData.serverUrl}` + aee.uri, uri: aee.uri }, name: name })
-                            } else {
-                                wx.showToast({ title: `${arr.errMsg}`, icon: 'error', duration: 2000 })
-                            }
-                        }
-                    })
+                async success(chooseRes) {
+                    const file = chooseRes.tempFilePaths;
+                    let res = await app.$apifile('files/test/upload', null, file[0])
+                    res = JSON.parse(res);
+                    if (res.errcode == '0') {
+                        that.triggerEvent('imgUpload', { data: { name: res.name, url: `${app.globalData.serverUrl}` + res.uri, uri: res.uri }, name: name })
+                    } else {
+                        wx.showToast({ title: `${res.errmsg}`, icon: 'error' })
+                    }
                 }
-            })
 
+            })
         },
         imgDel(e) {
             const that = this;

+ 3 - 3
icon/editoricon.wxss

@@ -1,9 +1,9 @@
 @font-face {
     font-family: "iconfont";
     /* Project id 3618777 */
-    src: url('//at.alicdn.com/t/c/font_3618777_jt1c9kwnge.woff2?t=1661840869173') format('woff2'),
-        url('//at.alicdn.com/t/c/font_3618777_jt1c9kwnge.woff?t=1661840869173') format('woff'),
-        url('//at.alicdn.com/t/c/font_3618777_jt1c9kwnge.ttf?t=1661840869173') format('truetype');
+    src: url('https://at.alicdn.com/t/c/font_3618777_jt1c9kwnge.woff2?t=1661840869173') format('woff2'),
+        url('https://at.alicdn.com/t/c/font_3618777_jt1c9kwnge.woff?t=1661840869173') format('woff'),
+        url('https://at.alicdn.com/t/c/font_3618777_jt1c9kwnge.ttf?t=1661840869173') format('truetype');
 }
 
 .iconfont {

+ 1 - 1
pages/index/index.js

@@ -1,4 +1,4 @@
-// pagesHome/home/index.js
+const app = getApp()
 Page({
 
     /**

+ 7 - 2
pagesCommon/test/index.js

@@ -1,4 +1,4 @@
-// pagesCommon/test/index.js
+const app = getApp()
 Page({
 
     /**
@@ -71,7 +71,12 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-
+        const that = this;
+        that.search()
+    },
+    async search() {
+        const res = await app.$api('test', 'GET', {});
+        console.log(res);
     },
 
     /**

+ 1 - 1
project.config.json

@@ -41,7 +41,7 @@
     },
     "compileType": "miniprogram",
     "libVersion": "2.19.4",
-    "appid": "wx2c50f82dae28a9f5",
+    "appid": "wx0fd4b616bc7cf3bb",
     "projectname": "miniprogram-92",
     "condition": {},
     "editorSetting": {

+ 1 - 1
project.private.config.json

@@ -1,6 +1,6 @@
 {
     "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
-    "projectname": "applets",
+    "projectname": "%E5%B0%8F%E7%A8%8B%E5%BA%8F",
     "setting": {
         "compileHotReLoad": false,
         "urlCheck": false

+ 8 - 0
utils/checkRes.js

@@ -0,0 +1,8 @@
+// 请求是否正确
+module.exports =  (res) => {
+    const { errcode = 0, errmsg } = res || {};
+    if (errcode === 0) {
+        return true;
+    }
+    return false;
+}

+ 51 - 0
utils/httpUtil.js

@@ -0,0 +1,51 @@
+// 请求地址
+const getDomain = (uri, type) => {
+    const app = getApp();
+    const { serverUrl, wechatUrl } = app.globalData
+    // 自定义
+    if (uri.includes('http')) return uri;
+    // 微信
+    if (uri.startsWith('/wechat/api')) return wechatUrl + uri;
+    // 地址前缀
+    else if (type) return serverUrl + `/projectadmin/${type}/api/` + uri;
+    // 常规
+    return serverUrl + '/projectadmin/api/' + uri;
+}
+export const $api = async (uri, method = 'GET', data, type) => {
+    // 请求地址
+    let baseUrl = getDomain(uri, type);
+    return new Promise((resolve, reject) => {
+        wx.request({
+            url: `${baseUrl}`,
+            method,
+            data,
+            header: {},
+            success: (res) => toResolve(resolve, res),
+            error: (e) => toReject(reject, e),
+        });
+    });
+}
+export const $apifile = async (uri, method, data, type) => {
+    // 请求地址
+    let baseUrl = getDomain(uri, type);
+    return new Promise((resolve, reject) => {
+        wx.uploadFile({
+            url: `https://broadcast.waityou24.cn/${uri}`,
+            filePath: data,
+            name: 'file',
+            formData: {},
+            success: (res) => toResolve(resolve, res),
+            error: (e) => toReject(reject, e),
+        })
+    });
+}
+const toResolve = (resolve, result) => {
+    if (result.statusCode === 200) resolve(result.data);
+    else {
+        console.error("请求失败");
+    }
+};
+const toReject = (reject, result) => {
+    console.error(result);
+    reject(result);
+};