123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- import Vue from 'vue'
- import store from './store'
- import App from './App'
- import share from './common/share.js'
- Vue.mixin(share)
- import cuCustom from './components/colorui/components/cu-custom.vue';
- Vue.component('cu-custom', cuCustom)
- import buy from './pages/buy/transaction.vue'
- Vue.component('buy', buy)
- import sale from './pages/sale/information.vue'
- Vue.component('sale', sale)
- import tarBar from './components/tarbar.vue'
- Vue.component('tar-bar', tarBar)
- import tran from './pages/tran/tran.vue'
- Vue.component('tran', tran)
- import appPush from './components/APPPush/index.js'
- Vue.use(appPush)
- import my from './pages/user/user.vue'
- Vue.component('my', my)
- // main.js
- import uView from "./components/uview-ui";
- Vue.use(uView);
- const vuexStore = require("@/store/$u.mixin.js");
- import helper from '@/common/helper.js'
- Vue.prototype.$helper = helper
- Vue.mixin(vuexStore);
- import webim from 'webim.js';
- Vue.config.productionTip = false
- Vue.prototype.$socket = webim;
- App.mpType = 'app'
- import * as filters from './filters'
- import * as config from './config'
- import utils from '@/util/util.js'
- import '@/common/directive.js'
- let urlAddress = 'liangxin.zthymaoyi.com'
- Vue.prototype.$url = 'https://' + urlAddress + '/upload/'
- Vue.prototype.$uploadUrl = config.def().baseUrlNew + 'appendix/api/uploadFiles'
- Vue.prototype.$ws = 'wss://' + urlAddress + '/chat'
- Vue.prototype.$ossUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/'
- Vue.prototype.utils = utils
- // 注册全局组件
- import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
- import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
- Vue.component('mescroll-body', MescrollBody)
- Vue.component('mescroll-uni', MescrollUni)
- // let urlAddress = 'localhost'
- // Vue.prototype.$url = 'https://liangxin.zthymaoyi.com/upload/'
- // Vue.prototype.$uploadUrl = 'https://liangxin.zthymaoyi.com/file/upload'
- // Vue.prototype.$ws = 'ws://'+urlAddress+':9999/chat'
- Object.keys(filters).forEach(key => {
- Vue.filter(key, filters[key])
- })
- //#ifdef H5
- let jweixin = require('./components/jweixin-module')
- let jwx = require('./components/jweixin-module/jwx')
- Vue.mixin({
- onShow() {
- jwx.configWeiXin(jwx => {})
- }
- })
- //#endif
- const defConfig = config.def
- const msg = (title, duration = 3500, mask = false, icon = 'none') => {
- //统一提示方便全局修改
- if (Boolean(title) === false) {
- return;
- }
- uni.showToast({
- title,
- duration,
- mask,
- icon
- });
- }
- let userInfo = undefined
- const logout = () => {
- userInfo = undefined
- uni.removeStorage({
- key: 'userInfo'
- })
- uni.removeStorage({
- key: 'rolesList'
- })
- uni.removeStorage({
- key: 'jurisdiction'
- })
- }
- const setUserInfo = (i) => {
- userInfo = i
- }
- const isVip = () => {
- return userInfo && userInfo.level
- }
- let loginLock = false
- // 原微信小程序请求方式
- const request = (_gp, _mt, data = {}, failCallback) => {
- //异步请求数据
- return new Promise(resolve => {
- if (!userInfo || !userInfo.accessToken) {
- userInfo = uni.getStorageSync('userInfo')
- }
- let accessToken = userInfo ? userInfo.accessToken : ''
- // let baseUrl = 'http://192.168.1.120:8090/'
- let baseUrl = config.def().baseUrl
- uni.request({
- url: baseUrl + '/m.api',
- data: {
- ...data,
- _gp,
- _mt
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- 'ACCESSTOKEN': accessToken
- },
- success: (res) => {
- if (res.statusCode === 200) {
- if (res.data.errno === 200) {
- resolve(res.data);
- } else if (res.data.errno === 10001) {
- if (failCallback) {
- failCallback(res.data)
- }
- uni.showModal({
- title: '提示',
- content: '您尚未登录,是否立即登录?',
- showCancel: true,
- confirmText: '登录',
- success: (e) => {
- if (e.confirm) {
- uni.navigateTo({
- url: '/pages/public/login'
- })
- }
- },
- fail: () => {},
- complete: () => {}
- })
- if (!loginLock) {
- loginLock = true
- // uni.showModal({
- // title: '提示',
- // content: '您尚未登录,是否立即登录?',
- // showCancel: false,
- // confirmText: '登录',
- // success: (e) => {
- // if (e.confirm) {
- // uni.navigateTo({
- // url: '/pages/public/login'
- // })
- // }
- // },
- // fail: () => {},
- // complete: () => {
- // loginLock = false
- // }
- // })
- }
- } else {
- if (failCallback) {
- failCallback(res.data)
- } else {
- if (res.data.errmsg) {
- uni.showToast({
- title: res.data.errmsg,
- icon: 'none',
- duration: 2000
- })
- } else {
- uni.showToast({
- title: "系统异常,请联系管理员",
- icon: 'none',
- duration: 2000
- })
- }
- }
- }
- }
- }
- })
- })
- }
- // 现app调用方式
- const doRequest = (method, url, data, header) => {
- var contentheader = 'application/json'
- if (header) {
- contentheader = header
- }
- // let baseUrl = config.def().baseUrl
- let baseUrl = config.def().baseUrlNew
- // 如果data为空
- // if (!data) var data = []
- // var arr = []
- // arr.push(data)
- // 接口需要验证的可以将json转成数组添加值再调用
- // 不需要的可以直接data:data
- return new Promise((resolve, reject) => {
- uni.request({
- method: method,
- url: baseUrl + url,
- // data: arr[0],
- data: data,
- header: {
- 'content-type': contentheader //'application/x-www-form-urlencoded; charset=UTF-8',
- },
- success: function(result) {
- // console.log(result,111111111111)
- // uni.hideLoading()
- resolve(result)
- // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑
-
- },
- fail: function(e) {
- uni.hideLoading()
- console.log('error in...', e)
- uni.showToast({
- title: e
- })
- // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑
- reject(e)
- },
- })
- })
- }
- const uploadImg = (successCallback) => {
- let baseUrl = config.def().baseUrl
- uni.chooseImage({
- sizeType: ['compressed'],
- success: function(res) {
- for (let i = 0; i < res.tempFilePaths.length; i++) {
- uni.request({
- url: baseUrl + '/upload',
- method: 'get',
- success: function(signRes) {
- uni.showLoading({
- title: '图片上传中',
- })
- let fileName = ('imgs/' + random_string(15) + get_suffix(res
- .tempFilePaths[i]))
- uni.uploadFile({
- url: signRes.data.baseUrl,
- filePath: res.tempFilePaths[i],
- name: 'file',
- formData: {
- name: res.tempFilePaths[i],
- key: fileName,
- policy: signRes.data.policy,
- OSSAccessKeyId: signRes.data.accessid,
- success_action_status: '200',
- signature: signRes.data.signature
- },
- success: function(uploadRes) {
- uni.hideLoading()
- if (uploadRes.statusCode === 200) {
- if (successCallback) {
- successCallback(signRes.data.baseUrl +
- fileName)
- } else {
- uni.showToast({
- title: '上传成功',
- icon: 'none'
- })
- }
- } else {
- uni.hideLoading()
- uni.showToast({
- title: '网络错误 code=' + uploadRes
- .statusCode,
- icon: 'none'
- })
- }
- }
- })
- }
- })
- }
- }
- })
- }
- function get_suffix(filename) {
- var pos = filename.lastIndexOf('.')
- var suffix = ''
- if (pos != -1) {
- suffix = filename.substring(pos)
- }
- return suffix;
- }
- function random_string(len) {
- len = len || 32;
- var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
- var maxPos = chars.length;
- var pwd = '';
- for (var i = 0; i < len; i++) {
- pwd += chars.charAt(Math.floor(Math.random() * maxPos));
- }
- return pwd;
- }
- const prePage = () => {
- let pages = getCurrentPages();
- let prePage = pages[pages.length - 2];
- // #ifdef H5
- return prePage;
- // #endif
- return prePage.$vm;
- }
- const globalData = {}
- Date.prototype.format = function(fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : ((
- "00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- Vue.config.productionTip = false
- Vue.prototype.$fire = new Vue();
- Vue.prototype.$store = store;
- Vue.prototype.$api = {
- msg,
- prePage,
- request,
- uploadImg,
- doRequest,
- logout,
- isVip,
- setUserInfo,
- defConfig,
- globalData
- };
- //#ifdef H5
- Vue.prototype.$jweixin = jweixin;
- //#endif
- App.mpType = 'app'
- const app = new Vue({
- ...App
- })
- app.$mount()
|