first commit
This commit is contained in:
@@ -0,0 +1,320 @@
|
||||
import { HttpRequest, StoreAssist, UploadAssist, ResultData } from '@/common/Common';
|
||||
import { BaseConfig } from './BaseConfig';
|
||||
export class Service extends BaseConfig {
|
||||
//获取API地址
|
||||
static ApiUrl(path : string) {
|
||||
return `${this.servesUrl}${path}`;
|
||||
}
|
||||
|
||||
//获取图片地址
|
||||
static GetpayImg(path : string) {
|
||||
if (path.startsWith('http') || path.startsWith('https')) {
|
||||
return path;
|
||||
} else {
|
||||
return `${this.payuploadUrl}${path}`;
|
||||
}
|
||||
}
|
||||
|
||||
//获取图片地址
|
||||
static GetMateUrlByImg(path : string) {
|
||||
if (path.startsWith('http') || path.startsWith('https')) {
|
||||
return path;
|
||||
} else {
|
||||
return `${this.imgUrl}${path}`;
|
||||
}
|
||||
}
|
||||
//获取音视频地址
|
||||
static GetMateUrlByMedia(path : string) {
|
||||
if (path.startsWith('http') || path.startsWith('https')) {
|
||||
return path;
|
||||
} else {
|
||||
return `${this.mediaUrl}${path}`;
|
||||
}
|
||||
}
|
||||
//获取登录账号token
|
||||
static GetUserToken() {
|
||||
return Service.GetStorageCache('token');
|
||||
}
|
||||
// 获取登录状态
|
||||
static GetUserIsLogin() {
|
||||
var token = this.GetUserToken();
|
||||
if (token == null || token == '') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//设置登录账户Token
|
||||
static SetUserToken(token : string) {
|
||||
this.SetStorageCache('token', token);
|
||||
}
|
||||
//清理登录账户Token
|
||||
static OffUserToken() {
|
||||
Service.DelStorageCache('token');
|
||||
uni.$emit('ImComOff', 'user');
|
||||
this.ClearUserStateData();
|
||||
}
|
||||
//获取登录账号状态信息
|
||||
static GetUserStateData() {
|
||||
return Service.GetStorageCache('StateDomain');
|
||||
}
|
||||
//设置当前登录账号状态信息
|
||||
static SetUserStateData() {
|
||||
return Service.GetStorageCache('StateDomain');
|
||||
}
|
||||
//清理当前登录账号状态信息
|
||||
static ClearUserStateData() {
|
||||
Service.DelStorageCache('StateDomain');
|
||||
}
|
||||
|
||||
//获取缓存
|
||||
static GetStorageCache(key : string) {
|
||||
return StoreAssist.Get(key);
|
||||
}
|
||||
//删除缓存
|
||||
static DelStorageCache(key : string) {
|
||||
StoreAssist.Delete(key);
|
||||
}
|
||||
//设置缓存
|
||||
static SetStorageCache(key : string, data : any) {
|
||||
StoreAssist.Set(key, data);
|
||||
}
|
||||
|
||||
/*****以下是基础方法调用与拦截器*****/
|
||||
|
||||
static Request(url : string, method : 'GET' | 'POST' | 'PUT' | undefined, data : object | any) {
|
||||
const token = Service.GetUserToken();
|
||||
|
||||
const _url = Service.ApiUrl(url);
|
||||
var result = HttpRequest.RequestWithToken(_url, method, token, data).then((retResult : any) => {
|
||||
if (retResult.statusCode == '200') {
|
||||
var obj = retResult.data;
|
||||
if (obj.code == 401) {
|
||||
//过期
|
||||
this.OffUserToken();
|
||||
this.Msg('登录过期,请重新登录')
|
||||
this.GoPage('/pages/login/login')
|
||||
return Promise.reject();
|
||||
} else if (obj.code == 40101) {
|
||||
//失效
|
||||
this.OffUserToken();
|
||||
this.GoPageDelse('/pages/mine/login/login');
|
||||
return Promise.reject();
|
||||
} else if (obj.code == 1004) {
|
||||
//资源不存在
|
||||
this.GoPageDelse('/pages/AppSet/404/404');
|
||||
return Promise.reject();
|
||||
// return new ResultData(-1, '', '');
|
||||
} else if (obj.code == 40188) {
|
||||
//无权限
|
||||
|
||||
this.GoPageDelse('/pages/AppSet/40188/40188');
|
||||
return Promise.reject();
|
||||
// return new ResultData(-1, '', '');
|
||||
} else if (obj.code == 1008) {
|
||||
//业务提示
|
||||
return new ResultData(obj.code, obj.msg, obj.data);
|
||||
} else {
|
||||
return new ResultData(obj.code, obj.msg, obj.data);
|
||||
}
|
||||
} else {
|
||||
return new ResultData(-1, '', '');
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
/*****以下是腾讯云oss上传*****/
|
||||
static UpLoadMedia(code : string, fileName : string, desire : string, path : string) {
|
||||
var result = this.Request(this.uploadUrl, 'GET', { code, fileName, desire }).then((retResult) => {
|
||||
if (retResult.code == 0) {
|
||||
var upOk = UploadAssist.Upload(retResult.data.url, path, retResult.data.cosData).then((upRet : any) => {
|
||||
if (upRet.statusCode == 200) {
|
||||
const retData : any = { code: retResult.data.code, file: retResult.data.file, cache: retResult.data.cache };
|
||||
return new ResultData(0, '上传成功!', retData);
|
||||
} else {
|
||||
this.Msg('上传失败!');
|
||||
return new ResultData(-1, '', '');
|
||||
}
|
||||
});
|
||||
return upOk;
|
||||
} else {
|
||||
this.Msg('上传失败!');
|
||||
return new ResultData(-1, retResult.msg,retResult.data);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/***********消息操作**************/
|
||||
static Msg(message : any, icon ?: any) : void {
|
||||
if (icon != null) {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: icon
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static Alert(msg : string, cb ?: any) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: msg,
|
||||
showCancel: false,
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
cb && cb();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static LoadIng(text : any) : void {
|
||||
uni.showLoading({
|
||||
title: text,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
static LoadClose() : void {
|
||||
uni.hideLoading();
|
||||
}
|
||||
|
||||
/**********跳转操作*********/
|
||||
|
||||
|
||||
static GoPageTab(path : string) : void {
|
||||
uni.switchTab({
|
||||
url: path
|
||||
});
|
||||
}
|
||||
|
||||
/**********跳转操作*********/
|
||||
static GoPage(path : string) : void {
|
||||
uni.navigateTo({
|
||||
url: path, //跳转的页面
|
||||
success: function (res) {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
}
|
||||
});
|
||||
}
|
||||
/**********跳转并删除当前页面操作*********/
|
||||
static GoPageDelse(path : string) : void {
|
||||
uni.redirectTo({
|
||||
url: path //跳转的页面
|
||||
});
|
||||
}
|
||||
|
||||
/**********返回上一页*********/
|
||||
static GoPageBack() : void {
|
||||
uni.navigateBack({ delta: 1 });
|
||||
}
|
||||
|
||||
/*****获取图片base64*****/
|
||||
static UpLoadMediaBase64(path : string) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
uni.uploadFile({
|
||||
url: 'http://cloud.pccsh.com/DefUp/UploadFileImgBase64', //仅为示例,非真实的接口地址
|
||||
filePath: path,
|
||||
name: 'file',
|
||||
success: (uploadFileRes) => {
|
||||
resolve(uploadFileRes);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/*****获取图片位置信息*****/
|
||||
//获取时间戳
|
||||
static GetTimeSpan(milliSecond : number) {
|
||||
return Date.now() + milliSecond;
|
||||
}
|
||||
|
||||
// 时间戳处理
|
||||
static formatDate(time : any, type : number) : string {
|
||||
const date = new Date(time);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1,并用0填充
|
||||
const day = String(date.getDate()).padStart(2, '0'); // 用0填充
|
||||
const hours = String(date.getHours()).padStart(2, '0'); // 用0填充
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0'); // 用0填充
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0'); // 用0填充
|
||||
if (type == 0) {
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
else if (type == 1) {
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||
} else if (type == 2) {
|
||||
return `${year}-${month}-${day}`;
|
||||
} else if (type == 3) {
|
||||
return `${hours}:${minutes}`;
|
||||
} else if (type == 4) {
|
||||
return `${year}${month}${day}`;
|
||||
}
|
||||
|
||||
else {
|
||||
return `${hours}:${minutes}`;
|
||||
}
|
||||
}
|
||||
|
||||
/*****节流*****/
|
||||
static throttle(fn: () => void, time: number) {
|
||||
let canRun: boolean = true;
|
||||
return function () {
|
||||
if (!canRun) return;
|
||||
canRun = false;
|
||||
setTimeout(() => {
|
||||
fn(); //可以不执行
|
||||
canRun = true;
|
||||
}, time);
|
||||
};
|
||||
}
|
||||
/*****防抖*****/
|
||||
static debounce<T extends (...args: any[]) => void>(fn: T, time: number): (...args: Parameters<T>) => void {
|
||||
let timerId: NodeJS.Timeout | null = null;
|
||||
|
||||
return (...args: Parameters<T>) => {
|
||||
if (timerId) {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
|
||||
timerId = setTimeout(() => {
|
||||
fn(...args); // 执行传入的函数
|
||||
timerId = null; // 清除定时器ID
|
||||
}, time);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 普通图片上传
|
||||
static uploadH5(path, dic, callback) {
|
||||
console.log(this.payuploadUrl,'xxx')
|
||||
uni.uploadFile({
|
||||
url: this.payuploadUrl+'/Upload/UploadFile',
|
||||
method: "POST",
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + Service.GetUserToken(),
|
||||
},
|
||||
formData: {
|
||||
"path": dic,
|
||||
},
|
||||
filePath: path,
|
||||
name: 'file',
|
||||
success: (data) => {
|
||||
let info = data.data
|
||||
callback(info)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<view class="liy-select-fixed" :class="openClass">
|
||||
<view class="liy-search-warp">
|
||||
<view class="liy-search-input">
|
||||
<view class="lsi-warp">
|
||||
<image src="../../static/liy-select/images/search.png" mode="widthFix"
|
||||
class="lsi-icon"></image>
|
||||
<input class="lsi-input" v-model="keyword" placeholder="请输入搜索内容" @input="getParamsList" />
|
||||
</view>
|
||||
</view>
|
||||
<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="lower">
|
||||
<view class="liy-search-list" v-if="outPutList.length > 0">
|
||||
<view class="liy-search-li" v-for="(item,index) in outPutList" :key="index"
|
||||
@click="mapSelectMenu(item,index)">
|
||||
<view class="liy-search-left">
|
||||
<view class="liy-search-title" v-if="titleKey">{{item[titleKey]}}
|
||||
</view>
|
||||
<view class="liy-search-title" v-else>未选择标题
|
||||
</view>
|
||||
<view class="liy-search-desc" v-if="subtitleKey">{{item[subtitleKey]}}</view>
|
||||
</view>
|
||||
<view class="liy-search-icon" v-if="mapSelectIndex == index">
|
||||
<image class="lsi-icon" src="../../static/liy-select/images/check_mark.png"
|
||||
mode="widthFix"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="liy-loading">
|
||||
<image class="liy-loading-img" src="../../static/liy-select/images/complete.png"
|
||||
mode="widthFix"></image>
|
||||
<view class="liy-loading-text">加载完成</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="liy-void">
|
||||
<image class="liy-void-img" src="../../static/liy-select/images/void.png"
|
||||
mode="widthFix"></image>
|
||||
<view class="liy-void-text">未查询到内容</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="liy-overlay" @click="closeOverlay" v-if="open == true"></view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name:'liy-select',
|
||||
props:{
|
||||
list:{
|
||||
type:Array,
|
||||
default:[]
|
||||
},
|
||||
titleKey:{
|
||||
type:[String,null],
|
||||
default: null
|
||||
},
|
||||
subtitleKey:{
|
||||
type:[String,null],
|
||||
default:null
|
||||
},
|
||||
open:{
|
||||
type:Boolean,
|
||||
default:false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
mapSelectIndex: null,
|
||||
keyword: "",
|
||||
outPutList: [],
|
||||
openClass:""
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
list (newList, oldList) {
|
||||
this.getParamsList();
|
||||
},
|
||||
open(newOpen,oldOpen){
|
||||
if(newOpen == true){
|
||||
this.openClass = "show";
|
||||
}else{
|
||||
this.openClass = "hide";
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getParamsList();
|
||||
},
|
||||
methods: {
|
||||
mapSelectMenu(item,index) {
|
||||
this.mapSelectIndex = index;
|
||||
this.$emit("change",item,index)
|
||||
this.$emit("close");
|
||||
},
|
||||
getParamsList() {
|
||||
var selectList = this.list;
|
||||
this.mapSelectIndex = null;
|
||||
if (!this.keyword) {
|
||||
this.outPutList = selectList;
|
||||
|
||||
return false;
|
||||
}
|
||||
var arr = [];
|
||||
for (var i = 0; i < selectList.length; i++) {
|
||||
let item = selectList[i];
|
||||
if (item[this.titleKey].indexOf(this.keyword) > -1) {
|
||||
arr.push(item);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
this.outPutList = arr;
|
||||
},
|
||||
lower() {
|
||||
|
||||
},
|
||||
closeOverlay() {
|
||||
this.$emit("close");
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.liy-overlay {
|
||||
transition-duration: 300ms;
|
||||
transition-timing-function: ease-out;
|
||||
position: fixed;
|
||||
inset: 0px;
|
||||
z-index: 100;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.liy-select-fixed {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 150;
|
||||
transition: transform .5s ease-in-out;
|
||||
transform: translateY(calc(100% + 40rpx));
|
||||
&.show {
|
||||
animation: showHandler 0.3s forwards;
|
||||
}
|
||||
|
||||
&.hide {
|
||||
animation: hideHandler 0.3s forwards;
|
||||
}
|
||||
|
||||
.liy-search-warp {
|
||||
background: #fff;
|
||||
border-radius: 10rpx 10rpx 0 0;
|
||||
|
||||
.liy-search-input {
|
||||
padding: 30rpx 40rpx;
|
||||
font-size: 28rpx;
|
||||
|
||||
.lsi-warp {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border: 2rpx solid #e3e3e3;
|
||||
padding: 16rpx 20rpx;
|
||||
border-radius: 50rpx;
|
||||
|
||||
.lsi-icon {
|
||||
width: 30rpx;
|
||||
height: 30rpx;
|
||||
}
|
||||
|
||||
.lsi-input {
|
||||
width: 90%;
|
||||
padding-left: 16rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.liy-search-list {
|
||||
.liy-search-li {
|
||||
padding: 20rpx 30rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-bottom: 1rpx solid #f7f7f7;
|
||||
min-height: 50rpx;
|
||||
|
||||
.liy-search-left {
|
||||
width: 90%;
|
||||
|
||||
.liy-search-title {
|
||||
font-size: 28rpx;
|
||||
line-height: 36rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.liy-search-desc {
|
||||
padding-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 36rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.liy-search-icon {
|
||||
.lsi-icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.scroll-Y {
|
||||
height: 500rpx;
|
||||
}
|
||||
|
||||
.liy-loading {
|
||||
color: #333;
|
||||
font-size: 26rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20rpx 0;
|
||||
|
||||
.liy-loading-img {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
// animation: turn 3s linear infinite;
|
||||
}
|
||||
|
||||
.liy-loading-text {
|
||||
padding-left: 12rpx;
|
||||
padding-right: 32rpx;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes turn {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
25% {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
75% {
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes showHandler {
|
||||
0% {
|
||||
transform: translateY(calc(100% + 40rpx));
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hideHandler {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
|
||||
100% {
|
||||
transform: translateY(calc(100% + 40rpx));
|
||||
}
|
||||
}
|
||||
|
||||
.liy-void {
|
||||
text-align: center;
|
||||
padding-top: 60rpx;
|
||||
|
||||
.liy-void-img {
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.liy-void-text {
|
||||
padding-top: 30rpx;
|
||||
font-size: 26rpx;
|
||||
color: #909090;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 325 B |
Reference in New Issue
Block a user