增加可配置人员统计页面

This commit is contained in:
闵 年泽 2025-02-11 09:34:29 +08:00 committed by ldeyun
parent 8624b29d37
commit 2183aab470
50 changed files with 692 additions and 207 deletions

View File

@ -1,3 +1,4 @@
# 开发环境
# 请求接口地址
VITE_REQUEST_BASE_URL = https://36.112.48.190
#VITE_REQUEST_BASE_URL = http://10.75.15.247:8080

View File

@ -1,3 +1,4 @@
# 生产环境
# 请求接口地址
VITE_REQUEST_BASE_URL = https://36.112.48.190
#VITE_REQUEST_BASE_URL = https://36.112.48.190
VITE_REQUEST_BASE_URL = http://10.75.15.247:8080

2
.gitignore vendored
View File

@ -61,3 +61,5 @@
/node_modules/.vite/deps/dayjs.js
/node_modules/.vite/deps/dayjs.js.map
/node_modules/.vite/deps/package.json
/uni_modules
/node_modules

View File

@ -81,3 +81,19 @@ export function cxcRyDataTongji(url, parm) { // 员工信息统计
data: parm
})
}
export function cxcRyDatAstatistics(parm) { // 员工分组统计
return https({
url: '/cxc_rlzy.zb/cxcRlzyZb/statistics',
method: 'get',
data: parm
})
}
export function cxcRyDatAstatisticsDetails(parm) { // 员工信息统计
return https({
url: '/cxc_rlzy.zb/cxcRlzyZb/details',
method: 'get',
data: parm
})
}

View File

@ -233,6 +233,14 @@
"navigationBarTitleText": "人员年龄分组统计信息",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/views/renliziyuan/renyuanxinxi/qttongji",
"style": {
"navigationBarTitleText": "其他统计信息",
"navigationBarTextStyle": "white"
}
}
],

View File

@ -8,10 +8,13 @@
</uni-section>
<uni-section title="统计信息" type="line">
<uni-card :is-shadow="false">
<button type="primary" @click="toTongji">分类统计</button>
<button type="primary" @click="toTongji">年龄段统计</button>
</uni-card>
<uni-card :is-shadow="false">
<button type="primary" @click="toQtTongji">其他统计</button>
</uni-card>
</uni-section>
</uni-card>
</view>
@ -29,6 +32,12 @@
url: "/pages/views/renliziyuan/renyuanxinxi/tongji"
})
}
function toQtTongji() {
uni.navigateTo({
url: "/pages/views/renliziyuan/renyuanxinxi/qttongji"
})
}
</script>
<style>

View File

@ -0,0 +1,349 @@
<template>
<view>
<view class="container" id="top1">
<uni-row style="margin-bottom: 10rpx;margin-left: 30rpx;margin-right: 30rpx;">
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx;margin-left: 30rpx;margin-right: 30rpx;">
<uni-col :span="24">
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode"
@change="onOrgCodeChange"></trq-depart-select>
</uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx;margin-left: 30rpx;margin-right: 30rpx;">
<uni-col :span="24">
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
</picker>
</uni-col>
</uni-row>
</view>
<!-- ECharts图表 -->
<view class="chart-container">
<l-echart ref="chart" @finished="initChart" @tap="onChartClick" />
</view>
<!-- 数据表格 -->
<uni-row style="margin-top: 10px; margin-left: 30rpx;margin-right: 30rpx;" v-if="personnelList.length>0">
<uni-col :span="3">
<view class="titleStyle">
序号
</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">
姓名
</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">
性别
</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">
年龄
</view>
</uni-col>
<uni-col :span="6">
<view class="titleStyle">
操作
</view>
</uni-col>
</uni-row>
<scroll-view scroll-y :style="{height: bottomHeight + 'px' }">
<uni-row style="margin-bottom: 10rpx;margin-left: 30rpx;margin-right: 30rpx;">
<view v-for="(item,index) in personnelList">
<uni-col :span="3">
<view class="dataStyle">
{{index+1}}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{item.xm}}
</view>
</uni-col><uni-col :span="5">
<view class="dataStyle">
{{item.xb_dictText}}
</view>
</uni-col><uni-col :span="5">
<view class="dataStyle">
{{item.nl}}
</view>
</uni-col>
<uni-col :span="6">
<view class="dataStyle">
<button size="mini" type="primary" @click="detail(item)">详情</button>
</view>
</uni-col>
</view>
</uni-row>
</scroll-view>
</view>
</template>
<script setup>
import {
ref,
reactive,
onMounted
} from 'vue';
import * as echarts from 'echarts';
import {
cxcRyDatAstatistics,
cxcRyDatAstatisticsDetails
} from '@/api/renyuan.js';
// tableData
const bottomHeight = ref(0);
//
const chart = ref(null);
const fieldList = ref([{
label: '性别',
value: 'xb'
},
{
label: '年龄',
value: 'nl'
},
{
label: '学历',
value: 'whcd1'
},
]); //
const selectedOrgCode = ref(''); // orgCode
const selectedOrgCodeLabel = ref('请选择单位'); //
const selectedField = ref(''); //
const selectedFieldLabel = ref('请选择字段'); //
const chartData = ref({}); //
const personnelList = ref([]); // initChart
const chartOption = ref({
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'category',
data: [],
},
yAxis: {
type: 'value',
},
series: [{
name: '数量',
type: 'bar',
data: [],
}, ],
})
function detail(record) {
// console.log(record)
uni.navigateTo({
url: "/pages/views/renliziyuan/renyuanxinxi/detail?data=" + encodeURIComponent(JSON.stringify(record))
})
}
onMounted(() => {
// #ifdef APP
getHeight();
// #endif
})
// #ifdef APP
const getHeight = () => {
//
const systemInfo = uni.getSystemInfoSync();
const screenHeight = systemInfo.screenHeight;
//
const query = uni.createSelectorQuery();
//
query
.select('#top1')
.boundingClientRect((rect1) => {
//
const topComponentsHeight = rect1.height
//
bottomHeight.value = screenHeight - topComponentsHeight - 415;
})
.exec();
};
// #endif
// ECharts length departChange
//
const initChart = () => {
setTimeout(async () => {
if (!chart.value) return
const myChart = await chart.value.init(echarts)
myChart.setOption(chartOption.value)
}, 300)
};
//
const updateChart = () => {
if (!chartInstance) return;
const {
xb,
number
} = chartData.value;
chartInstance.setOption({
xAxis: {
data: xb,
},
series: [{
data: number,
}, ],
});
};
//
const fetchStatisticsData = async () => {
if (!selectedOrgCode.value || !selectedField.value) return;
try {
const res = await cxcRyDatAstatistics({
orgCode: selectedOrgCode.value,
field: selectedField.value,
});
console.log(res)
chartData.value = res.data;
updateChart();
} catch (error) {
console.error('获取统计数据失败:', error);
}
};
// delimiter
const fetchPersonnelList = async (ldhthList) => {
try {
const res = await cxcRyDatAstatisticsDetails({
ldhth: ldhthList
});
console.log(res)
personnelList.value = res.data;
} catch (error) {
console.error('获取人员列表失败:', error);
}
};
//
const onOrgCodeChange = (e) => {
const index = e.detail.value;
selectedOrgCode.value = orgCodeList.value[index].value;
selectedOrgCodeLabel.value = orgCodeList.value[index].label;
fetchStatisticsData();
};
const onFieldChange = (e) => {
const index = e.detail.value;
selectedField.value = fieldList.value[index].value;
selectedFieldLabel.value = fieldList.value[index].label;
fetchStatisticsData();
};
const onChartClick = (e) => {
const {
ldhth
} = chartData.value;
if (ldhth && ldhth.length > 0) {
fetchPersonnelList(ldhth);
}
};
</script>
<style scoped>
.container {
margin: 20, 20, 20, 20rpx;
}
.input-group {
display: flex;
gap: 20rpx;
margin-bottom: 30rpx;
}
.input {
flex: 1;
border: 1rpx solid #ddd;
padding: 15rpx;
border-radius: 8rpx;
}
.query-btn {
background: #007AFF;
color: white;
padding: 0 40rpx;
border-radius: 8rpx;
}
.stats-box {
display: flex;
justify-content: space-around;
margin: 30rpx 0;
padding: 20rpx;
background: #f8f8f8;
border-radius: 12rpx;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.label {
font-size: 24rpx;
color: #666;
}
.value {
font-size: 36rpx;
font-weight: bold;
color: #0000ff;
}
.chart-container {
height: 400rpx;
margin-top: 20rpx;
}
.titleStyle {
font-size: 12px;
color: #747474;
line-height: 30px;
height: 30px;
background: #F2F9FC;
text-align: center;
vertical-align: middle;
border-left: 1px solid #919191;
border-bottom: 1px solid #919191;
;
}
/* 内容样式 */
.dataStyle {
max-font-size: 14px;
/* 最大字体限制 */
min-font-size: 10px;
/* 最小字体限制 */
font-size: 12px;
color: #00007f;
line-height: 30px;
height: 30px;
font-weight: 500;
text-align: center;
vertical-align: middle;
border-bottom: 1px solid #919191;
border-left: 1px solid #919191;
text-overflow: ellipsis;
}
</style>

View File

@ -7,7 +7,7 @@ import {isDef} from '../isDef'
* @returns null null
*/
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export function addUnit(value?: string | number): string | null {
if (!isDef(value)) {
return null;
@ -19,7 +19,7 @@ export function addUnit(value?: string | number): string | null {
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
function addUnit(value: string): string
function addUnit(value: number): string
function addUnit(value: any|null): string|null {

View File

@ -1,2 +1,3 @@
import {cubicBezier} from './bezier';
export let ease = cubicBezier(0.25, 0.1, 0.25, 1);
export let linear = cubicBezier(0,0,1,1);

View File

@ -1,10 +1,10 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.uts'
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif

View File

@ -1,14 +1,14 @@
// @ts-nocheck
import { ComponentPublicInstance } from 'vue'
import { ease } from './ease';
import type { ComponentPublicInstance } from 'vue'
import { ease, linear } from './ease';
import { Timeline, Animation } from './';
export type UseTransitionOptions = {
duration ?: number
immediate ?: boolean
context ?: ComponentPublicInstance
}
// #ifndef APP-IOS || APP-ANDROID
import { ref, watch, Ref } from '@/uni_modules/lime-shared/vue'
// #ifndef UNI-APP-X && APP
import { ref, watch, type Ref } from '@/uni_modules/lime-shared/vue'
export function useTransition(percent : Ref<number>|(() => number), options : UseTransitionOptions) : Ref<number> {
const current = ref(0)
@ -47,7 +47,7 @@ export function useTransition(percent : Ref<number>|(() => number), options : Us
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
type UseTransitionReturnType = Ref<number>
export function useTransition(source : any, options : UseTransitionOptions) : UseTransitionReturnType {
const outputRef : Ref<number> = ref(0)
@ -69,7 +69,7 @@ export function useTransition(source : any, options : UseTransitionOptions) : Us
0,
ease,
nowValue => {
outputRef.value = nowValue //nowValue < 0.0001 ? 0 : Math.abs(v - nowValue) < 0.00001 ? v : nowValue;
outputRef.value = nowValue
clearTimeout(timer)
if(outputRef.value == v){
timer = setTimeout(()=>{
@ -78,14 +78,17 @@ export function useTransition(source : any, options : UseTransitionOptions) : Us
}, duration)
}
}
), null
),
null
);
}
if (context != null && typeof source == 'string') {
context.$watch(source, watchFunc, { immediate } as WatchOptions)
} else {
watch(source, watchFunc, { immediate } as WatchOptions)
} else if(typeof source == 'function'){
watch(source, watchFunc, { immediate })
} else if(source instanceof Ref<number>){
watch(source as Ref<number>, watchFunc, { immediate })
}
const stop = ()=>{

View File

@ -1,3 +1,4 @@
import { raf, cancelRaf} from '../raf'
// @ts-nocheck
export class Timeline {
state : string
@ -13,7 +14,7 @@ export class Timeline {
this.state = 'Initiated';
}
start() {
if (!(this.state === 'Initiated')) return;
if (!(this.state == 'Initiated')) return;
this.state = 'Started';
let startTime = Date.now();
@ -43,20 +44,26 @@ export class Timeline {
if (animation == null) return
this.animations.delete(animation);
}
clearTimeout(this.tickHandler);
// cancelAnimationFrame(this.tickHandler);
if (this.state != 'Started') return
this.tickHandler = setTimeout(() => {
this.tickHandler = raf(()=>{
this.tick!()
}, 1000 / 60)
// this.tickHandlers.push(this.tickHandler)
})
this.tickHandlers.push(this.tickHandler)
}
if(this.tick != null) {
this.tick!()
}
}
pause() {
if (!(this.state === 'Started')) return;
this.state = 'Paused';
this.pauseStart = Date.now();
clearTimeout(this.tickHandler);
cancelRaf(this.tickHandler);
// cancelRaf(this.tickHandler);
}
resume() {
if (!(this.state === 'Paused')) return;

View File

@ -1,10 +1,8 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif
// #ifdef UNI-APP-X
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.uts'
// #endif
// #endif

View File

@ -1,9 +1,9 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.uts'
// #endif

View File

@ -1,6 +1,6 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
// #ifdef MP-ALIPAY
interface My {
@ -57,11 +57,11 @@ export function canIUseCanvas2d(): boolean {
// #ifdef MP-TOUTIAO
return gte('1.78.0');
// #endif
// #ifdef UNI-APP-X && WEB || UNI-APP-X && APP
return true;
// #endif
// #ifndef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO
return false
// #endif
// #ifdef APP-IOS || APP-ANDROID || APP-NVUE || APP-VUE
return false;
// #endif
}

View File

@ -1,3 +1,26 @@
## 0.2.72025-01-17
- fix: 针对canvas 平台判断优化
## 0.2.62025-01-09
- feat: 增加`areaData`中国省市区数据
## 0.2.52025-01-07
- fix: animation在app上类型问题
## 0.2.42025-01-04
- feat: getRect类型问题
## 0.2.32025-01-01
- chore: unitConvert使用uni.rpx2px
## 0.2.22024-12-11
- chore: 动画使用`requestAnimationFrame`
## 0.2.12024-11-20
- feat: 增加`characterLimit`
## 0.2.02024-11-14
- fix: vue2的类型问题
## 0.1.92024-11-14
- feat: 增加`shuffle`
## 0.1.82024-10-08
- fix: vue2 条件编译 // #ifdef APP-IOS || APP-ANDROID 会生效
## 0.1.72024-09-23
- fix: raf 类型跟随版本变更
## 0.1.62024-07-24
- fix: vue2 app ts需要明确的后缀所有补全
- chore: 减少依赖

View File

@ -1,10 +1,10 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.ts'
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif

View File

@ -15,6 +15,9 @@
import { debounce } from '@/uni_modules/lime-shared/debounce'
import { fillZero } from '@/uni_modules/lime-shared/fillZero'
import { floatAdd } from '@/uni_modules/lime-shared/floatAdd'
import { floatMul } from '@/uni_modules/lime-shared/floatMul'
import { floatDiv } from '@/uni_modules/lime-shared/floatDiv'
import { floatSub } from '@/uni_modules/lime-shared/floatSub'
import { getClassStr } from '@/uni_modules/lime-shared/getClassStr'
import { getCurrentPage } from '@/uni_modules/lime-shared/getCurrentPage'
import { getStyleStr } from '@/uni_modules/lime-shared/getStyleStr'
@ -40,91 +43,102 @@
import { toNumber } from '@/uni_modules/lime-shared/toNumber'
import { unitConvert } from '@/uni_modules/lime-shared/unitConvert'
import { getCurrentInstance } from '@/uni_modules/lime-shared/vue'
import { capitalizedAmount } from '@/uni_modules/lime-shared/capitalizedAmount'
// #ifdef VUE2
type UTSJSONObject = any
// #endif
const context = getCurrentInstance()
getRect('#shared', context!).then(res =>{
console.log('res', res.bottom)
})
getAllRect('#shared', context).then(res =>{
console.log('res', res)
})
// getRect('#shared', context!).then(res =>{
// console.log('res', res.bottom)
// })
// getAllRect('#shared', context).then(res =>{
// console.log('res', res)
// })
console.log('camelCase::', camelCase("hello world"));
console.log('camelCase::', camelCase("my_name_is_john", true));
console.log('canIUseCanvas2d::', canIUseCanvas2d());
console.log('clamp::', clamp(5 ,0, 10));
console.log('cloneDeep::', cloneDeep<UTSJSONObject>({a:5}));
console.log('closest::', closest([1, 3, 5, 7, 9], 6));
// console.log('camelCase::', camelCase("hello world"));
// console.log('camelCase::', camelCase("my_name_is_john", true));
// console.log('canIUseCanvas2d::', canIUseCanvas2d());
// console.log('clamp::', clamp(5 ,0, 10));
// console.log('cloneDeep::', cloneDeep<UTSJSONObject>({a:5}));
// console.log('closest::', closest([1, 3, 5, 7, 9], 6));
const saveData = (data: any) => {
//
console.log(`Saving data: ${data}`);
}
// const saveData = (data: any) => {
// //
// console.log(`Saving data: ${data}`);
// }
const debouncedSaveData = debounce(saveData, 500);
debouncedSaveData('Data 1');
debouncedSaveData('Data 2');
// const debouncedSaveData = debounce(saveData, 500);
// debouncedSaveData('Data 1');
// debouncedSaveData('Data 2');
console.log('fillZero', fillZero(1))
console.log('floatAdd', floatAdd(0.1, 0.2))
console.log('getClassStr', getClassStr({hover: true}))
console.log('getStyleStr', getStyleStr({ color: 'red', fontSize: '16px', backgroundColor: '', border: null }))
console.log('hasOwn', hasOwn({a: true}, 'key'))
console.log('isBase64::', isBase64("SGVsbG8sIFdvcmxkIQ=="));
console.log('isBrowser::', isBrowser);
console.log('isDef::', isDef('6'));
console.log('isEmpty::', isEmpty({a: true}));
// console.log('fillZero', fillZero(1))
// console.log('floatAdd', floatAdd(0.1, 0.2), floatAdd(1.05, 0.05), floatAdd(0.1, 0.7), floatAdd(0.0001, 0.0002), floatAdd(123.456 , 789.012))
// console.log('floatMul', floatMul(0.1, 0.02), floatMul(1.0255, 100))
// console.log('floatDiv', floatDiv(10.44, 100), floatDiv(1.0255, 100), floatDiv(5.419909340994699, 0.2))
// console.log('floatSub', floatSub(0.4, 0.1), floatSub(1.0255, 100))
const now = () : number => System.nanoTime() / 1_000_000.0
console.log('capitalizedAmount', capitalizedAmount(0.4))
console.log('capitalizedAmount', capitalizedAmount(100))
console.log('capitalizedAmount', capitalizedAmount(100000000))
console.log('capitalizedAmount', capitalizedAmount('2023.04'))
console.log('capitalizedAmount', capitalizedAmount(-1024))
console.log('now', now(), Date.now())
// console.log('getClassStr', getClassStr({hover: true}))
// console.log('getStyleStr', getStyleStr({ color: 'red', fontSize: '16px', backgroundColor: '', border: null }))
// console.log('hasOwn', hasOwn({a: true}, 'key'))
// console.log('isBase64::', isBase64("SGVsbG8sIFdvcmxkIQ=="));
// console.log('isBrowser::', isBrowser);
// console.log('isDef::', isDef('6'));
// console.log('isEmpty::', isEmpty({a: true}));
const b = () =>{}
console.log('isFunction::', isFunction(b));
console.log('isNumber::', isNumber('6'));
console.log('isNumeric::', isNumeric('6'));
console.log('isObject::', isObject({}));
// const b = () =>{}
// console.log('isFunction::', isFunction(b));
// console.log('isNumber::', isNumber('6'));
// console.log('isNumeric::', isNumeric('6'));
// console.log('isObject::', isObject({}));
const promise = ():Promise<boolean> => {
return new Promise((resolve) => {
resolve(true)
})
}
const a = promise()
console.log('isPromise::', isPromise(a));
console.log('isString::', isString('null'));
console.log('kebabCase::', kebabCase('my love'));
console.log('raf::', raf(()=>{
console.log('raf:::1')
}));
console.log('doubleRaf::', doubleRaf(()=>{
console.log('doubleRaf:::1')
}));
console.log('random', random(0, 10))
console.log('random', random(0, 1, 2))
console.log('range', range(0, 10, 2))
console.log('sleep', sleep(300).then(res => {
console.log('log')
}))
// const promise = ():Promise<boolean> => {
// return new Promise((resolve) => {
// resolve(true)
// })
// }
// const a = promise()
// console.log('isPromise::', isPromise(a));
// console.log('isString::', isString('null'));
// console.log('kebabCase::', kebabCase('my love'));
// console.log('raf::', raf(()=>{
// console.log('raf:::1')
// }));
// console.log('doubleRaf::', doubleRaf(()=>{
// console.log('doubleRaf:::1')
// }));
// console.log('random', random(0, 10))
// console.log('random', random(0, 1, 2))
// console.log('range', range(0, 10, 2))
// console.log('sleep', sleep(300).then(res => {
// console.log('log')
// }))
const handleScroll = (a: string) => {
console.log("Scroll event handled!", a);
}
// const handleScroll = (a: string) => {
// console.log("Scroll event handled!", a);
// }
// // 使 handleScroll 500
const throttledScroll = throttle(handleScroll, 500);
throttledScroll('5');
const page = getCurrentPage()
console.log('getCurrentPage::', page)
// // // 使 handleScroll 500
// const throttledScroll = throttle(handleScroll, 500);
// throttledScroll('5');
// const page = getCurrentPage()
// console.log('getCurrentPage::', page)
console.log('toArray', toArray<number>(5))
console.log('toBoolean', toBoolean(5))
console.log('toNumber', toNumber('5'))
console.log('unitConvert', unitConvert('5'))
// console.log('toArray', toArray<number>(5))
// console.log('toBoolean', toBoolean(5))
// console.log('toNumber', toNumber('5'))
// console.log('unitConvert', unitConvert('5'))
// uni.getImageInfo({
// src: '/static/logo.png',
@ -132,6 +146,9 @@
// console.log('res', res)
// }
// })
export default {
}
</script>
<style>

View File

@ -1,5 +1,5 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
import {isBrowser} from '../isBrowser'
class Image {
currentSrc: string | null = null
@ -63,8 +63,9 @@ export function createImage(canvas?: any): HTMLImageElement | UniImage {
// #endif
// #ifdef APP-IOS || APP-ANDROID
export function createImage(){
console.error('当前环境不支持')
// #ifdef UNI-APP-X && APP
export function createImage():Image{
// console.error('当前环境不支持')
return new Image()
}
// #endif

View File

@ -1,10 +1,10 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.ts'
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif

View File

@ -1,9 +1,9 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.ts'
// #endif

View File

@ -1,6 +1,6 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
import { isNumber } from '../isNumber'
import { isString } from '../isString'
import { isDef } from '../isDef'
@ -13,7 +13,7 @@ import { isDef } from '../isDef'
*/
export function getClassStr<T>(obj : T) : string {
let classNames : string[] = [];
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
if (obj instanceof UTSJSONObject) {
(obj as UTSJSONObject).toMap().forEach((value, key) => {
if (isDef(value)) {
@ -30,7 +30,7 @@ export function getClassStr<T>(obj : T) : string {
})
}
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
// 遍历对象的属性
for (let key in obj) {
// 检查属性确实属于对象自身且其值为true

View File

@ -1,9 +1,9 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.uts'
// #endif

View File

@ -16,7 +16,7 @@ export const getLocalFilePath = (path : string) => {
// #endif
// #ifdef APP-ANDROID || APP-IOS
// #ifdef UNI-APP-X && APP
export { getResourcePath as getLocalFilePath } from '@/uni_modules/lime-file-utils'
// export const getLocalFilePath = (path : string) : string => {
// let uri = path

View File

@ -1,9 +1,9 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.uts'
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif

View File

@ -1,5 +1,5 @@
// @ts-nocheck
export function getRect(selector : string, context: ComponentInternalInstance):Promise<NodeInfo> {
export function getRect(selector : string, context: ComponentPublicInstance):Promise<NodeInfo> {
return new Promise((resolve)=>{
uni.createSelectorQuery().in(context).select(selector).boundingClientRect(res =>{
resolve(res as NodeInfo)
@ -7,7 +7,7 @@ export function getRect(selector : string, context: ComponentInternalInstance):P
})
}
export function getAllRect(selector : string, context: ComponentInternalInstance):Promise<NodeInfo[]> {
export function getAllRect(selector : string, context: ComponentPublicInstance):Promise<NodeInfo[]> {
return new Promise((resolve)=>{
uni.createSelectorQuery().in(context).selectAll(selector).boundingClientRect(res =>{
resolve(res as NodeInfo[])

View File

@ -12,7 +12,7 @@ const dom = uni.requireNativePlugin('dom')
* @param node node
* @returns Promise
*/
export function getRect(selector : string, context : ComponentInternalInstance, node: boolean = false) {
export function getRect(selector : string, context : ComponentInternalInstance|ComponentPublicInstance, node: boolean = false) {
// 之前是个对象,现在改成实例,防止旧版会报错
if(context== null) {
return Promise.reject('context is null')
@ -67,7 +67,7 @@ export function getRect(selector : string, context : ComponentInternalInstance,
};
export function getAllRect(selector : string, context: ComponentInternalInstance, node:boolean = false) {
export function getAllRect(selector : string, context: ComponentInternalInstance|ComponentPublicInstance, node:boolean = false) {
if(context== null) {
return Promise.reject('context is null')
}

View File

@ -1,12 +1,12 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
interface CSSProperties {
[key : string] : string | number | null
}
// #endif
// #ifdef VUE3
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
type CSSProperties = UTSJSONObject
// #endif
// #endif
@ -26,7 +26,7 @@ export function toLowercaseSeparator(key : string):string {
*/
export function getStyleStr(style : CSSProperties) : string {
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
let styleStr = '';
style.toMap().forEach((value, key) => {
if(value !== null && value != '') {
@ -35,7 +35,7 @@ export function getStyleStr(style : CSSProperties) : string {
})
return styleStr
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
return Object.keys(style)
.filter(
(key) =>

View File

@ -1,9 +1,9 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.ts'
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif

View File

@ -13,10 +13,10 @@ export function isDef(value: unknown): boolean {
// #ifdef UNI-APP-X
export function isDef(value : any|null) : boolean {
// #ifdef APP-ANDROID || APP-IOS
// #ifdef UNI-APP-X && APP
return value != null;
// #endif
// #ifndef APP-ANDROID || APP-IOS
// #ifndef UNI-APP-X && APP
return value != null && value != undefined;
// #endif
}

View File

@ -16,7 +16,7 @@ import {isNumber} from '../isNumber'
*/
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export function isEmpty(value : any | null) : boolean {
// 为null
if(!isDef(value)){
@ -55,7 +55,7 @@ export function isEmpty(value : any | null) : boolean {
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export function isEmpty(value: any): boolean {
// 检查是否为null或undefined
if (value == null) {

View File

@ -5,12 +5,12 @@
* @returns true false
*/
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export const isFunction = (val: any):boolean => typeof val == 'function';
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export const isFunction = (val: unknown): val is Function =>
typeof val === 'function';
// #endif

View File

@ -19,7 +19,7 @@ export function isNumber(value: any|null): boolean {
// #ifdef APP-IOS
return ['Int8', 'UInt8','Int16','UInt16','Int32','UInt32','Int64','UInt64','Int','UInt','Float','Float16','Float32','Float64','Double', 'number'].includes(typeof value)
// #endif
// #ifndef APP-ANDROID || APP-IOS
// #ifndef UNI-APP-X && APP
return typeof value === 'number' && !isNaN(value);
// #endif
}

View File

@ -6,14 +6,14 @@
* @returns true false
*/
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export function isNumeric(value: string | number | undefined | null): boolean {
return /^(-)?\d+(\.\d+)?$/.test(value);
}
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
import {isNumber} from '../isNumber';
import {isString} from '../isString';
export function isNumeric(value : any|null) : boolean {

View File

@ -5,14 +5,14 @@
* @returns true false
*/
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export const isObject = (val : unknown) : val is Record<any, any> =>
val !== null && typeof val === 'object';
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export const isObject = (val : any | null) : boolean =>{
return val !== null && typeof val === 'object';
}

View File

@ -4,7 +4,7 @@
* @param str
* @returns true false
*/
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
// export const isString = (str: unknown): str is string => typeof str === 'string';
export function isString (str: unknown): str is string {
return typeof str == 'string'
@ -12,8 +12,8 @@ export function isString (str: unknown): str is string {
// #endif
// #ifdef APP-IOS || APP-ANDROID
export function isString (str: any): boolean {
// #ifdef UNI-APP-X && APP
export function isString (str: any|null): boolean {
return typeof str == 'string'
}
// #endif

View File

@ -12,10 +12,10 @@
export function kebabCase(str : string, separator : string = "-") : string {
return str
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
.replace(/[A-Z]/g, (match : string, _ : number, _ : string) : string => `${separator}${match.toLowerCase()}`) // 将大写字母替换为连接符加小写字母
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
.replace(/[A-Z]/g, (match : string) : string => `${separator}${match.toLowerCase()}`) // 将大写字母替换为连接符加小写字母
// #endif
.replace(/[\s_-]+/g, separator) // 将空格、下划线和短横线替换为指定连接符

View File

@ -1,7 +1,7 @@
{
"id": "lime-shared",
"displayName": "lime-shared",
"version": "0.1.6",
"version": "0.2.7",
"description": "本人插件的几个公共函数获取当前页图片的base64转临时路径图片的exif信息等",
"keywords": [
"lime-shared",
@ -50,7 +50,8 @@
"App": {
"app-vue": "y",
"app-uvue": "y",
"app-nvue": "y"
"app-nvue": "y",
"app-harmony": "u"
},
"H5-mobile": {
"Safari": "y",

View File

@ -1,9 +1,9 @@
// @ts-nocheck
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export * from './vue.ts'
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export * from './uvue.uts'
// #endif

View File

@ -1,10 +1,10 @@
// @ts-nocheck
// #ifdef APP-IOS || APP-ANDROID
export * from './vue.ts'
// #ifdef UNI-APP-X && APP
export * from './uvue'
// #endif
// #ifndef APP-IOS || APP-ANDROID
export * from './uvue.ts'
// #ifndef UNI-APP-X && APP
export * from './vue'
// #endif

View File

@ -1,12 +1,11 @@
// @ts-nocheck
// import {isBrowser} from '../isBrowser'
// 是否支持被动事件监听
export const supportsPassive = true;
// #ifdef uniVersion < 4.25
// 请求动画帧
export function raf(fn: TimerCallback): number {
return setTimeout(fn, 1000 / 30);
return setTimeout(fn, 1000 / 60);
}
// 取消动画帧
@ -14,7 +13,36 @@ export function cancelRaf(id: number) {
clearTimeout(id);
}
// 双倍动画帧
export function doubleRaf(fn: TimerCallback): void {
raf(() => raf(fn)); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
raf(():number => raf(fn)); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
}
// #endif
// #ifdef uniVersion >= 4.25
// 请求动画帧
export function raf(fn: UniAnimationFrameCallback): number
export function raf(fn: UniAnimationFrameCallbackWithNoArgument): number
export function raf(fn: any): number {
if(typeof fn == 'UniAnimationFrameCallback') {
return requestAnimationFrame(fn as UniAnimationFrameCallback);
} else {
return requestAnimationFrame(fn as UniAnimationFrameCallbackWithNoArgument);
}
}
// 取消动画帧
export function cancelRaf(id: number) {
cancelAnimationFrame(id);
}
// 双倍动画帧
export function doubleRaf(fn: UniAnimationFrameCallback): void
export function doubleRaf(fn: UniAnimationFrameCallbackWithNoArgument): void
export function doubleRaf(fn: any): void {
raf(():number => raf(fn)); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
}
// #endif

View File

@ -1,5 +1,4 @@
// @ts-nocheck
// import { isBrowser } from '../isBrowser'
type Callback = () => void//Function
// 是否支持被动事件监听
export const supportsPassive = true;
@ -7,7 +6,7 @@ export const supportsPassive = true;
// 请求动画帧
export function raf(fn : Callback) : number {
// #ifndef WEB
return setTimeout(fn, 1000 / 30); // 请求动画帧
return setTimeout(fn, 1000 / 60); // 请求动画帧
// #endif
// #ifdef WEB
return requestAnimationFrame(fn); // 请求动画帧

View File

@ -32,6 +32,7 @@ import {getRect} from '@/uni_modules/lime-shared/getRect'
+ [camelCase](#api_camelCase): 字符串转换为 camelCase 或 PascalCase 风格的命名约定
+ [kebabCase](#api_kebabCase): 将字符串转换为指定连接符的命名约定
+ [closest](#api_closest): 在给定数组中找到最接近目标数字的元素
+ [shuffle](#api_shuffle): 将给定的数组打乱
+ [isBase64](#api_isBase64): 判断字符串是否为base64
+ [isNumber](#api_isNumber): 检查一个值是否为数字类型
+ [isNumeric](#api_isNumeric): 检查一个值是否为数字类型或表示数字的字符串
@ -371,6 +372,19 @@ closest([1, 3, 5, 7, 9], 6) // 5
| √ | √ |
### shuffle <a id="api_shuffle"></a>
- 在给定数组中找到最接近目标数字的元素
```js
shuffle([1, 3, 5, 7, 9])
```
##### 兼容性
| uni-app | uni-app x |
|------------|----------------------------------|
| √ | √ |
### isBase64 <a id="api_isBase64"></a>
- 判断字符串是否为base64

View File

@ -6,7 +6,7 @@
*/
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
function sleep(delay: number = 300):Promise<boolean> {
return new Promise((resolve):void => {setTimeout(() => {resolve(true)}, delay)});
}
@ -16,7 +16,7 @@ export {
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export const sleep = (delay: number = 300) =>
new Promise(resolve => setTimeout(resolve, delay));

View File

@ -6,7 +6,7 @@
* @returns
*/
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export function throttle(fn: (...args: any[]) => void, delay: number) {
let flag = true; // 标记是否可以执行函数
@ -24,7 +24,7 @@ export function throttle(fn: (...args: any[]) => void, delay: number) {
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
// type Rfun = (...args: any[]) => void
// type Rfun = (...args: any[]) => void

View File

@ -4,12 +4,12 @@
* @param item
* @returns
*/
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export const toArray = <T>(item: T | T[]): T[] => Array.isArray(item) ? item : [item];
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
export function toArray<T extends any>(item: any): T[] {
return Array.isArray(item) ? item as T[] : [item as T]// as T[]
};

View File

@ -7,7 +7,7 @@ import { isString } from '../isString'
// function toBoolean(value : number) : boolean;
// function toBoolean(value : boolean) : boolean;
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
function toBoolean(value : any | null) : boolean {
// 根据输入值的类型,返回相应的布尔值
// if (isNumber(value)) {
@ -29,7 +29,7 @@ function toBoolean(value : any | null) : boolean {
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
function toBoolean(value : any | null) : value is NonNullable<typeof value> {
return !!value//value !== null && value !== undefined;
}

View File

@ -5,7 +5,7 @@
* @returns
*/
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
// function toNumber(val: string): number
// function toNumber(val: string): string
function toNumber(val: string): number|null {
@ -15,7 +15,7 @@ function toNumber(val: string): number|null {
export {toNumber}
// #endif
// #ifndef APP-IOS || APP-ANDROID
// #ifndef UNI-APP-X && APP
export function toNumber(val: string): number | string {
const n = parseFloat(val); // 使用 parseFloat 函数将字符串转换为浮点数
return isNaN(n) ? val : n; // 使用 isNaN 函数判断是否为非数字,返回转换后的数字或原始字符串

View File

@ -7,8 +7,8 @@ import { isNumeric } from '../isNumeric'
* @param value
* @returns 0
*/
// #ifndef APP-IOS || APP-ANDROID
export function unitConvert(value : string | number) : number {
// #ifndef UNI-APP-X && APP
export function unitConvert(value : string | number, base: number = 0) : number {
// 如果是字符串数字
if (isNumeric(value)) {
return Number(value);
@ -21,12 +21,15 @@ export function unitConvert(value : string | number) : number {
return 0;
}
const unit = results[3];
value = parseFloat(value);
const _value = parseFloat(value);
if (unit === 'rpx') {
return uni.upx2px(value);
return uni.upx2px(_value);
}
if (unit === 'px') {
return value * 1;
return _value * 1;
}
if(unit == '%') {
return _value / 100 * base
}
// 如果是其他单位,可以继续添加对应的转换逻辑
}
@ -35,9 +38,9 @@ export function unitConvert(value : string | number) : number {
// #endif
// #ifdef APP-IOS || APP-ANDROID
// #ifdef UNI-APP-X && APP
import { isNumber } from '../isNumber'
export function unitConvert(value : any | null) : number {
export function unitConvert(value : any | null, base: number = 0) : number {
if (isNumber(value)) {
return value as number
}
@ -53,13 +56,17 @@ export function unitConvert(value : any | null) : number {
return 0;
}
const unit = results[3];
const v = parseFloat(value);
const _value = parseFloat(value);
if (unit == 'rpx') {
const { windowWidth } = uni.getWindowInfo()
return windowWidth / 750 * v;
// const { windowWidth } = uni.getWindowInfo()
// return windowWidth / 750 * _value;
return uni.rpx2px(_value)
}
if (unit == 'px') {
return v;
return _value;
}
if(unit == '%') {
return _value / 100 * base
}
// 如果是其他单位,可以继续添加对应的转换逻辑
}