|
- <script>
- import http from '@/http/api.js'
- import {
- options
- } from '@/http/config.js';
- import {
- Base64
- } from '@/utils/base64.js';
- import {
- clientId,
- clientSecret
- } from '@/common/setting'
- export default{
- methods:{
- // 暂存一个跨页面变量 (与 this.GET_PARAM 成对使用)
- SET_PARAM(val) {
- this.SET_GLOBAL('pageParam', val)
- },
-
- // 获取之前暂存的跨页面变量 (与 this.SET_PARAM 成对使用)
- GET_PARAM() {
- return this.GET_GLOBAL('pageParam')
- },
-
- // 进入某个页面
- NAV_TO(url, param, usePageParam) {
- uni.navigateTo({
- url: this.handleNav(url, param, usePageParam)
- })
- },
- // 返回上个页面
- // delta 参数为返回的次数
- NAV_BACK(delta = 1) {
- uni.navigateBack({
- delta
- })
- },
- // 跳转到某个页面,跳转后无法返回
- JUMP_TO(url, param, usePageParam) {
- uni.redirectTo({
- url: this.handleNav(url, param, usePageParam)
- })
- },
- // 转到某个 Tab 页
- TAB_TO(url, param) {
- uni.switchTab({
- url: this.handleNav(url, param, true)
- })
- },
- // 【内部方法】处理页面跳转 url 和参数
- handleNav(url, param, usePageParam) {
- let query = ''
- if (param && usePageParam) {
- this.SET_PARAM(param)
- } else if (param && !usePageParam) {
- query += '?' + Object.entries(param).filter(([k, v]) => k && v).map(([k, v]) => k + '=' + v).join('&')
- }
-
- return url + query
- },
- // 设置页面标题
- SET_TITLE(title) {
- uni.setNavigationBarTitle({
- title
- })
- },
- // 监听一个全局事件
- ON(name, func) {
- uni.$on(name, func)
- },
-
- // 仅单次监听一个全局事件
- ONCE(name, func) {
- uni.$once(name, func)
- },
-
- // 触发一个全局事件
- EMIT(name, data) {
- uni.$emit(name, data)
- },
-
- // 移除全局事件监听器
- OFF(name, func) {
- uni.$off(name, func)
- },
- // 二次确认提示框
- CONFIRM(content='是否确认执行此操作?'){
- return new Promise((resolve)=>{
- uni.showModal({
- title: '提示',
- content: content,
- cancelText: "取消",
- confirmText: "确认",
- confirmColor: '#F2C827',
- cancelColor: '#9E9E9E',
- success: function (res) {
- if (res.confirm) {
- resolve(true)
- } else if (res.cancel) {
- resolve(false)
- }
- }
- });
- })
- },
- TOAST(title){
- uni.showToast({
- icon: "none",
- title,
- duration: 2000,
- });
- },
- UPLOAD_FILE(filePath){
- let that = this
- // 假设有token值需要在头部需要携带
- let header = {}
- let accessToken = uni.getStorageSync('accessToken');
- if (accessToken) {
- header['Blade-Auth'] = 'bearer ' + accessToken;
- }
- // 客户端认证参数
- header['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
- console.log(filePath)
- return new Promise(resovle=>{
- uni.uploadFile({
- url:options.baseURL + '/api/blade-resource/oss/endpoint/put-uplaod-file?bucketName=',
- filePath,
- name:'file',
- header,
- success(e){
- if(e.statusCode == 200){
- let res = JSON.parse(e.data)
- if(res.code == 200){
- resovle(res.data)
- }else{
- resovle(res.msg)
- }
- }else{
- resovle(false)
- }
- },
- fail(e){
- console.log('fail',e)
- resovle(false)
- },
- })
- })
- },
- DELETE_FILE(attachIds){
- return http.request({
- url: '/api/blade-resource/oss/endpoint/remove-file-attachIds',
- method: 'post',
- params:{attachIds}
- })
- },
- // 显示 loading 提示框
- // title 为提示文字
- // mask 为是否禁止点击
- LOADING(title, mask = true) {
- uni.showLoading({
- title,
- mask
- })
- },
- // 停止展示 loading 提示框
- HIDE_LOADING() {
- uni.hideLoading()
- },
- // url获取文件流
- DOWNLOAD_FILE(url){
- return uni.downloadFile({
- url
- })
- },
- //复制链接
- COPYLINK(item){
- return new Promise((resolve)=>{
- uni.setClipboardData({
- data: item, // 要复制的路径
- success: function(res) {
- resolve(true)
- // uni.getClipboardData({
- // success: function(data) {
- // resolve(true)
- // },
- // fail: function(data1) {
- // resolve(false)
- // }
- // });
- }
- });
- })
-
- },
- },
- }
- </script>
|