|
@@ -1,14 +1,11 @@
|
|
|
import App from './App'
|
|
|
|
|
|
-// #ifndef VUE3
|
|
|
import Vue from 'vue'
|
|
|
import './uni.promisify.adaptor'
|
|
|
|
|
|
-import request from './utils/request.js'
|
|
|
-Vue.prototype.$request = request;
|
|
|
-
|
|
|
import uView from "uview-ui";
|
|
|
Vue.use(uView);
|
|
|
+Vue.config.productionTip = false
|
|
|
|
|
|
import './css/style.css'
|
|
|
|
|
@@ -29,66 +26,139 @@ Vue.component('send-type', sendType);
|
|
|
import useListTitle from './components/use-list-title/use-list-title.vue';
|
|
|
Vue.component('use-list-title', useListTitle);
|
|
|
|
|
|
-// const autoLogin = async () => { // 小程序自动登录
|
|
|
-// return new Promise(resolve => {
|
|
|
-// console.log('1111111111111111111111111111')
|
|
|
-// uni.login({
|
|
|
-// success: async (res) => {
|
|
|
-// const result = await request('post', '/miniLogin', {
|
|
|
-// code: res.code,
|
|
|
-// appid:'000000'
|
|
|
-// // appid: Vue.prototype.appId
|
|
|
-// })
|
|
|
-// if (result) {
|
|
|
-// uni.setStorageSync("token", result.data.token);
|
|
|
-// // await Vue.prototype.getUser()
|
|
|
-// resolve(true)
|
|
|
-// } else {
|
|
|
-// uni.showModal({
|
|
|
-// title: '温馨提示',
|
|
|
-// content: '您尚未注册,是否前往注册?',
|
|
|
-// showCancel: true,
|
|
|
-// confirmText: '去注册',
|
|
|
-// success: (response) => {
|
|
|
-// if (response.confirm) {
|
|
|
-// // 用户点击确定
|
|
|
-// uni.navigateTo({
|
|
|
-// url: '/pages/bindPhone/bindPhone'
|
|
|
-// })
|
|
|
-// resolve(true)
|
|
|
-// } else if (response.cancel) {
|
|
|
-// // 用户点击取消
|
|
|
-// resolve(false)
|
|
|
-// }
|
|
|
-// },
|
|
|
-// fail: () => {
|
|
|
-// resolve(false)
|
|
|
-// }
|
|
|
-// })
|
|
|
-// }
|
|
|
-// },
|
|
|
-// fail: (e) => {
|
|
|
-// resolve(false)
|
|
|
-// }
|
|
|
-// })
|
|
|
-// })
|
|
|
-// }
|
|
|
-// autoLogin()
|
|
|
-Vue.config.productionTip = false
|
|
|
-App.mpType = 'app'
|
|
|
+// 配置项
|
|
|
+const config = process.env.ENV_PATH ? require(process.env.ENV_PATH) : require('./env/dev.js')
|
|
|
+Vue.prototype.serverPath = config.serverPath // 请求路径
|
|
|
+Vue.prototype.serverFilePath = config.serverFilePath // 文件路径
|
|
|
+Vue.prototype.appName = config.name // 应用名称
|
|
|
+Vue.prototype.appVersion = config.appVersion // 小程序版本
|
|
|
+Vue.prototype.webSocketURL = config.webSocketURL // socket 链接
|
|
|
+Vue.prototype.logo = config.logo //
|
|
|
+Vue.prototype.appId = config.appId // 微信小程序 appid
|
|
|
+Vue.prototype.$isIphoneX = false
|
|
|
+
|
|
|
+Vue.prototype.$request = function(method, url, data, isJSON, hideLoading, showErrMsg) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ if (!hideLoading) {
|
|
|
+ uni.showLoading({
|
|
|
+ title: '请稍后...'
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 过滤 null,undefind,'' 的参数
|
|
|
+ for (let key in data) {
|
|
|
+ if (data[key] === null || data[key] === undefined || data[key] === '') {
|
|
|
+ delete data[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const token = uni.getStorageSync('token');
|
|
|
+ url = url.indexOf('http') === 0 ? url : `${Vue.prototype.serverPath}${url}`;
|
|
|
+ uni.request({
|
|
|
+ url,
|
|
|
+ method,
|
|
|
+ data,
|
|
|
+ header: {
|
|
|
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
|
+ // 'Content-Type': isJSON ? '' : 'application/x-www-form-urlencoded',
|
|
|
+ 'Authorization': `Bearer ${token}`,
|
|
|
+ 'tenantId': Vue.prototype.tenantId
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ uni.hideLoading();
|
|
|
+ if (res.data.code === 0) {
|
|
|
+ resolve(res.data);
|
|
|
+ } else {
|
|
|
+ if (showErrMsg) {
|
|
|
+ resolve({
|
|
|
+ result: false,
|
|
|
+ msg: res.data.msg
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ resolve(false);
|
|
|
+ if (this.$refs && this.$refs.uNotify) {
|
|
|
+ this.$refs.uNotify.show({
|
|
|
+ type: 'error',
|
|
|
+ top: 0,
|
|
|
+ message: res.data.msg,
|
|
|
+ icon: 'error-circle'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ uni.hideLoading();
|
|
|
+ resolve(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
+Vue.prototype.autoLogin = async () => { // 小程序自动登录
|
|
|
+ return new Promise(resolve => {
|
|
|
+ uni.login({
|
|
|
+ success: async (res) => {
|
|
|
+ const result = await Vue.prototype.$request('post', '/miniLogin', {
|
|
|
+ code: res.code,
|
|
|
+ appid: '000000'
|
|
|
+ //appid: Vue.prototype.appId
|
|
|
+ })
|
|
|
+ if (result) {
|
|
|
+ uni.setStorageSync("token", result.data.access_token);
|
|
|
+ //await Vue.prototype.getUser()
|
|
|
+ resolve(true)
|
|
|
+ } else {
|
|
|
+ uni.showModal({
|
|
|
+ title: '温馨提示',
|
|
|
+ content: '您尚未注册,是否前往注册?',
|
|
|
+ showCancel: true,
|
|
|
+ confirmText: '去注册',
|
|
|
+ success: (response) => {
|
|
|
+ if (response.confirm) {
|
|
|
+ // 用户点击确定
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/bindPhone/bindPhone'
|
|
|
+ })
|
|
|
+ resolve(true)
|
|
|
+ } else if (response.cancel) {
|
|
|
+ // 用户点击取消
|
|
|
+ resolve(false)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ resolve(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (e) => {
|
|
|
+ resolve(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 拼接文件完整地址
|
|
|
+Vue.prototype.getFilePath = (path) => {
|
|
|
+ return `${Vue.prototype.serverFilePath}${path}`
|
|
|
+}
|
|
|
+
|
|
|
+App.mpType = 'app'
|
|
|
const app = new Vue({
|
|
|
- ...App
|
|
|
+ ...App
|
|
|
})
|
|
|
app.$mount()
|
|
|
-// #endif
|
|
|
+
|
|
|
|
|
|
// #ifdef VUE3
|
|
|
-import { createSSRApp } from 'vue'
|
|
|
+import {
|
|
|
+ createSSRApp
|
|
|
+} from 'vue'
|
|
|
export function createApp() {
|
|
|
- const app = createSSRApp(App)
|
|
|
- return {
|
|
|
- app
|
|
|
- }
|
|
|
+ const app = createSSRApp(App)
|
|
|
+ return {
|
|
|
+ app
|
|
|
+ }
|
|
|
}
|
|
|
// #endif
|