This commit is contained in:
commit
8ea14a72c9
|
@ -16,6 +16,10 @@ this.$api.getList(params).then(res => {
|
||||||
export const GetPlanByDate = (data) =>
|
export const GetPlanByDate = (data) =>
|
||||||
request.get("/api/App/GetPlanByDate", data);
|
request.get("/api/App/GetPlanByDate", data);
|
||||||
|
|
||||||
|
// 根据日期获取计划
|
||||||
|
export const GetTodayPlanList = (data) =>
|
||||||
|
request.get("/api/App/GetTodayPlanList", data);
|
||||||
|
|
||||||
// 今日完成情况
|
// 今日完成情况
|
||||||
export const TodayCompletion = (data) =>
|
export const TodayCompletion = (data) =>
|
||||||
request.post("/api/App/TodayCompletion", data);
|
request.post("/api/App/TodayCompletion", data);
|
||||||
|
|
|
@ -10,15 +10,24 @@
|
||||||
<u-dropdown :title-size="42" active-color="#211D2F">
|
<u-dropdown :title-size="42" active-color="#211D2F">
|
||||||
<u-dropdown-item
|
<u-dropdown-item
|
||||||
v-model="dropdownValue"
|
v-model="dropdownValue"
|
||||||
title="保洁计划"
|
:title="dataInfo.planName"
|
||||||
:options="dropdownOptions"
|
:options="dropdownOptions"
|
||||||
|
@change="changeDropdown"
|
||||||
></u-dropdown-item>
|
></u-dropdown-item>
|
||||||
</u-dropdown>
|
</u-dropdown>
|
||||||
</view>
|
</view>
|
||||||
</u-navbar>
|
</u-navbar>
|
||||||
<view class="area-info">
|
<view class="area-info">
|
||||||
<view class="name">2024年11月21号</view>
|
<view class="name">{{
|
||||||
<view class="position"> 08:30~11:30</view>
|
dataInfo.planDate ? dataInfo.planDate.split("T")[0] : ""
|
||||||
|
}}</view>
|
||||||
|
<view class="position">
|
||||||
|
<span v-if="dataInfo.beginTime && dataInfo.endTime">
|
||||||
|
{{ minutesToTime(dataInfo.beginTime) }}~{{
|
||||||
|
minutesToTime(dataInfo.endTime)
|
||||||
|
}}
|
||||||
|
</span>
|
||||||
|
</view>
|
||||||
<view class="tabs">
|
<view class="tabs">
|
||||||
<view
|
<view
|
||||||
@click="changeTab(i)"
|
@click="changeTab(i)"
|
||||||
|
@ -32,24 +41,29 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="arealist">
|
<view class="arealist">
|
||||||
<view class="block-info">
|
<view class="block-info" v-for="item in dataInfo.areas" :key="item.id">
|
||||||
<view class="schedule">待保洁</view>
|
<view v-if="!item.isCompleted" class="schedule schedule-wait"
|
||||||
|
>待保洁</view
|
||||||
|
>
|
||||||
|
<view v-else class="schedule schedule-completed">已完成</view>
|
||||||
|
|
||||||
<view class="name">
|
<view class="name">
|
||||||
<u-icon size="40" :name="posIcon"></u-icon>
|
<u-icon size="40" :name="posIcon"></u-icon>
|
||||||
<view class="text">东大门北侧_门2</view>
|
<view class="text">{{ item.aeraNmae }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="type">
|
<view class="type">
|
||||||
<view class="value">区域类型</view>
|
<view class="value">区域类型</view>
|
||||||
<u-tag
|
<u-tag
|
||||||
text="室外"
|
:text="item.areaType"
|
||||||
class="tag"
|
class="tag"
|
||||||
border-color="transparent"
|
border-color="transparent"
|
||||||
type="success"
|
:type="item.areaType === '室外' ? 'success' : 'primary'"
|
||||||
/>
|
/>
|
||||||
<u-tag text="特殊" border-color="transparent" type="warning" />
|
<!-- 特殊先隐藏,没有这个字段 -->
|
||||||
|
<!-- <u-tag text="特殊" border-color="transparent" type="warning" /> -->
|
||||||
</view>
|
</view>
|
||||||
<view class="illustrate">
|
<view class="illustrate">
|
||||||
{{ "需要清理整个户外通道/保持跑道整洁花坛边落叶清扫" }}
|
{{ item.note }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -86,14 +100,16 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { GetPlanInfoAreaList } from "@/api/apiList";
|
import { GetPlanInfoAreaList, GetTodayPlanList } from "@/api/apiList";
|
||||||
|
|
||||||
|
import { minutesToTime } from "@/utils/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
posIcon: require("@/static/images/pos-icon.png"),
|
posIcon: require("@/static/images/pos-icon.png"),
|
||||||
selectIdx: 0,
|
selectIdx: 0,
|
||||||
dropdownValue: 1,
|
dropdownValue: "",
|
||||||
dropdownOptions: [
|
dropdownOptions: [
|
||||||
{
|
{
|
||||||
label: "保洁计划1",
|
label: "保洁计划1",
|
||||||
|
@ -128,20 +144,36 @@ export default {
|
||||||
successShow:false,
|
successShow:false,
|
||||||
// 刷卡失败弹窗
|
// 刷卡失败弹窗
|
||||||
errorShow:false,
|
errorShow:false,
|
||||||
|
dataInfo: {
|
||||||
|
planName: "",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
// dropdownTitle() {
|
||||||
|
// // 通过 dropdownValue 匹配 对应的项,展示 label
|
||||||
|
// const item = this.dropdownOptions.find(
|
||||||
|
// (item) => item.value === this.dropdownValue
|
||||||
|
// );
|
||||||
|
// return item ? item.label : "";
|
||||||
|
// },
|
||||||
|
},
|
||||||
|
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
this.paramsId = options.id;
|
// this.paramsId = options.id;
|
||||||
|
this.dropdownValue = options.id;
|
||||||
window.nfcFn = this.nfcResFn;
|
window.nfcFn = this.nfcResFn;
|
||||||
// this.nfcResFn();
|
// this.nfcResFn();
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
// this.getPlanInfoAreaList();
|
this.getTodayPlanList();
|
||||||
|
this.getPlanInfoAreaList();
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
minutesToTime,
|
||||||
nfcResFn(data){
|
nfcResFn(data){
|
||||||
if(false){
|
if(false){
|
||||||
console.log('%c%s', 'color:red', 'nfc刷卡成功');
|
console.log('%c%s', 'color:red', 'nfc刷卡成功');
|
||||||
|
@ -165,18 +197,36 @@ export default {
|
||||||
openFn(){},
|
openFn(){},
|
||||||
closeFn(){},
|
closeFn(){},
|
||||||
changeTab(i) {
|
changeTab(i) {
|
||||||
console.log(i);
|
|
||||||
this.selectIdx = i;
|
this.selectIdx = i;
|
||||||
|
|
||||||
|
this.getPlanInfoAreaList();
|
||||||
|
},
|
||||||
|
|
||||||
|
changeDropdown(e) {
|
||||||
|
this.dropdownValue = e;
|
||||||
|
|
||||||
|
this.getPlanInfoAreaList();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取今日计划
|
||||||
|
async getTodayPlanList() {
|
||||||
|
const res = await GetTodayPlanList();
|
||||||
|
if (res.succeed) {
|
||||||
|
this.dropdownOptions = res.data.map((item) => ({
|
||||||
|
label: item.name,
|
||||||
|
value: item.id,
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取计划区域列表
|
// 获取计划区域列表
|
||||||
async getPlanInfoAreaList() {
|
async getPlanInfoAreaList() {
|
||||||
const res = await GetPlanInfoAreaList({
|
const res = await GetPlanInfoAreaList({
|
||||||
id: this.paramsId,
|
id: this.dropdownValue,
|
||||||
// isCompleted: false,
|
isCompleted: this.selectIdx === 0 ? true : false,
|
||||||
});
|
});
|
||||||
if (res.succeed) {
|
if (res.succeed) {
|
||||||
console.log("res...", res);
|
this.dataInfo = res.data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -185,7 +235,7 @@ export default {
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.content {
|
.content {
|
||||||
height: 100vh;
|
// height: 100vh;
|
||||||
background: #f7f8fc;
|
background: #f7f8fc;
|
||||||
.slot-wrap {
|
.slot-wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -254,6 +304,7 @@ export default {
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border-radius: 18rpx;
|
border-radius: 18rpx;
|
||||||
padding: 65rpx 46rpx;
|
padding: 65rpx 46rpx;
|
||||||
|
margin-bottom: 32rpx;
|
||||||
.schedule {
|
.schedule {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
@ -261,14 +312,25 @@ export default {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
background-color: #feeded; /* 背景颜色 */
|
// background-color: #feeded; /* 背景颜色 */
|
||||||
color: white;
|
color: white;
|
||||||
width: 160rpx;
|
width: 160rpx;
|
||||||
height: 45rpx;
|
height: 45rpx;
|
||||||
font-size: 30rpx;
|
font-size: 30rpx;
|
||||||
color: #db3636;
|
// color: #db3636;
|
||||||
border-bottom-left-radius: 500rpx; /* 切角 */
|
border-bottom-left-radius: 500rpx; /* 切角 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.schedule-completed {
|
||||||
|
color: #4278f4;
|
||||||
|
background-color: #e5ebff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.schedule-wait {
|
||||||
|
color: #db3636;
|
||||||
|
background-color: #feeded;
|
||||||
|
}
|
||||||
|
|
||||||
.name {
|
.name {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
@ -15,13 +15,6 @@
|
||||||
@click="toggleDate"
|
@click="toggleDate"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<u-calendar
|
|
||||||
v-model="showCalendar"
|
|
||||||
mode="range"
|
|
||||||
:max-date="maxDate"
|
|
||||||
@change="changeDate"
|
|
||||||
></u-calendar>
|
|
||||||
</u-navbar>
|
</u-navbar>
|
||||||
|
|
||||||
<view
|
<view
|
||||||
|
@ -50,7 +43,7 @@
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="planList" :class="{ activeList: activeTab === 'incomplete' }">
|
<view class="planList" :class="{ activeList: activeTab === 'incomplete' }">
|
||||||
<view class="plan-item">
|
<!-- <view class="plan-item">
|
||||||
<view class="plan-header">
|
<view class="plan-header">
|
||||||
<image
|
<image
|
||||||
src="/static/images/icon-date.png"
|
src="/static/images/icon-date.png"
|
||||||
|
@ -69,34 +62,44 @@
|
||||||
北大门右侧操场跑道/南广场升旗台/A区第二食堂3楼
|
北大门右侧操场跑道/南广场升旗台/A区第二食堂3楼
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view> -->
|
||||||
<view class="plan-item">
|
<view class="plan-item" v-for="(item, index) in planList" :key="index">
|
||||||
<view class="plan-header">
|
<view class="plan-header">
|
||||||
<image
|
<image
|
||||||
src="/static/images/icon-date.png"
|
src="/static/images/icon-date.png"
|
||||||
mode="scaleToFill"
|
mode="scaleToFill"
|
||||||
style="width: 40rpx; height: 40rpx"
|
style="width: 40rpx; height: 40rpx"
|
||||||
/>
|
/>
|
||||||
<view class="date">05-21</view>
|
<view class="date">{{ item.date }}</view>
|
||||||
<view>1天前</view>
|
<view>{{ item.date ? getDateDiff(item.date) : "-" }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="plan-content">
|
<view class="plan-content">
|
||||||
<view class="plan-content-top">
|
<view class="plan-content-top">
|
||||||
<view class="place">校门A区教学楼</view>
|
<view class="place">{{ item.name }}</view>
|
||||||
<u-tag text="9:00~12:00" type="info" border-color="transparent" />
|
<u-tag text="9:00~12:00" type="info" border-color="transparent" />
|
||||||
</view>
|
</view>
|
||||||
<view class="plan-content-main">
|
<view class="plan-content-main">
|
||||||
北大门右侧操场跑道/南广场升旗台/A区第二食堂3楼
|
{{ item.areas }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<u-calendar
|
||||||
|
v-model="showCalendar"
|
||||||
|
mode="range"
|
||||||
|
:max-date="maxDate"
|
||||||
|
@change="changeDate"
|
||||||
|
></u-calendar>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { GetPlanList } from "@/api/apiList";
|
import { GetPlanList } from "@/api/apiList";
|
||||||
|
|
||||||
|
import { GetNowTime } from "@/utils/common";
|
||||||
|
import { getDateDiff } from "@/utils/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -105,11 +108,25 @@ export default {
|
||||||
maxDate: "2049-12-31",
|
maxDate: "2049-12-31",
|
||||||
|
|
||||||
showCalendar: false,
|
showCalendar: false,
|
||||||
dateRange: "",
|
|
||||||
|
// 请求参数
|
||||||
|
params: {
|
||||||
|
// '0 1 2'
|
||||||
|
"Item1.IsCompleted": 0,
|
||||||
|
dateBegin: GetNowTime(new Date()),
|
||||||
|
dateEnd: GetNowTime(new Date()),
|
||||||
|
},
|
||||||
|
|
||||||
|
// 计划列表
|
||||||
|
planList: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {},
|
created() {
|
||||||
|
this.getPlanList();
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getDateDiff,
|
||||||
|
|
||||||
toggleDate() {
|
toggleDate() {
|
||||||
this.showCalendar = !this.showCalendar;
|
this.showCalendar = !this.showCalendar;
|
||||||
},
|
},
|
||||||
|
@ -118,9 +135,18 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
changeDate(e) {
|
changeDate(e) {
|
||||||
console.log("333", e);
|
this.params.dateBegin = e.startDate;
|
||||||
|
this.params.dateEnd = e.endDate;
|
||||||
|
this.getPlanList();
|
||||||
|
},
|
||||||
|
|
||||||
this.dateRange = e;
|
// 获取计划列表
|
||||||
|
async getPlanList() {
|
||||||
|
const res = await GetPlanList(this.params);
|
||||||
|
|
||||||
|
if (res.succeed) {
|
||||||
|
this.planList = res.data;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -128,7 +154,8 @@ export default {
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.content {
|
.content {
|
||||||
height: 100vh;
|
// height: 100vh;
|
||||||
|
padding-bottom: 100rpx;
|
||||||
background: #f7f8fc;
|
background: #f7f8fc;
|
||||||
.selectTab {
|
.selectTab {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -89,27 +89,27 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.getUserInfo();
|
// this.getUserInfo();
|
||||||
const that = this;
|
// const that = this;
|
||||||
uni.getSystemInfo({
|
// uni.getSystemInfo({
|
||||||
success: function (res) {
|
// success: function (res) {
|
||||||
console.log("res", res);
|
// console.log("res", res);
|
||||||
that.version = res.appVersion;
|
// that.version = res.appVersion;
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
uni.$on("refresh", (e) => {
|
// uni.$on("refresh", (e) => {
|
||||||
this.getUserInfo();
|
// this.getUserInfo();
|
||||||
uni.$off("refresh");
|
// uni.$off("refresh");
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
|
|
||||||
// 下拉刷新
|
// 下拉刷新
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
//console.log('refresh');
|
//console.log('refresh');
|
||||||
this.getUserInfo();
|
// this.getUserInfo();
|
||||||
uni.stopPullDownRefresh(); //停止刷新
|
// uni.stopPullDownRefresh(); //停止刷新
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
297
utils/utils.js
297
utils/utils.js
|
@ -4,13 +4,13 @@
|
||||||
* @param {String} icon icon图片
|
* @param {String} icon icon图片
|
||||||
* @param {Number} duration 提示时间
|
* @param {Number} duration 提示时间
|
||||||
*/
|
*/
|
||||||
export function toast(title, icon = 'none', duration = 1500) {
|
export function toast(title, icon = "none", duration = 1500) {
|
||||||
if(title) {
|
if (title) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title,
|
title,
|
||||||
icon,
|
icon,
|
||||||
duration
|
duration,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,10 @@ export function toast(title, icon = 'none', duration = 1500) {
|
||||||
*/
|
*/
|
||||||
export function Jump(url) {
|
export function Jump(url) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: url
|
url: url,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提示信息
|
* 提示信息
|
||||||
* **/
|
* **/
|
||||||
|
@ -35,23 +33,20 @@ export function showModal(title, msg, showCancel) {
|
||||||
title: title,
|
title: title,
|
||||||
content: msg,
|
content: msg,
|
||||||
showCancel: showCancel,
|
showCancel: showCancel,
|
||||||
success: function(res) {
|
success: function (res) {},
|
||||||
|
});
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function showLoading(content) {
|
export function showLoading(content) {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: content
|
title: content,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 隐藏loading
|
* 隐藏loading
|
||||||
* **/
|
* **/
|
||||||
export function hideLoading() {
|
export function hideLoading() {
|
||||||
uni.hideLoading()
|
uni.hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -66,7 +61,7 @@ export function getTimStamp() {
|
||||||
* 生成随机数
|
* 生成随机数
|
||||||
*/
|
*/
|
||||||
export function getNonce() {
|
export function getNonce() {
|
||||||
var t = '';
|
var t = "";
|
||||||
for (var i = 0; i < 12; i++) {
|
for (var i = 0; i < 12; i++) {
|
||||||
t += Math.floor(Math.random() * 10);
|
t += Math.floor(Math.random() * 10);
|
||||||
}
|
}
|
||||||
|
@ -77,9 +72,9 @@ export function getNonce() {
|
||||||
* ***/
|
* ***/
|
||||||
export function getnoncestr() {
|
export function getnoncestr() {
|
||||||
let len = len || 32;
|
let len = len || 32;
|
||||||
var $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
var $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
var maxPos = $chars.length;
|
var maxPos = $chars.length;
|
||||||
var pwd = '';
|
var pwd = "";
|
||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
|
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
|
||||||
}
|
}
|
||||||
|
@ -104,7 +99,6 @@ export function UrlParamHash(url) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一键复制 uni.setClipboardData
|
* 一键复制 uni.setClipboardData
|
||||||
* 用法:
|
* 用法:
|
||||||
|
@ -112,19 +106,19 @@ export function UrlParamHash(url) {
|
||||||
* 2. 利用async await
|
* 2. 利用async await
|
||||||
* 3. await setClipboardData(需要复制的文本)
|
* 3. await setClipboardData(需要复制的文本)
|
||||||
*/
|
*/
|
||||||
const setClipboardData = (text) =>{
|
const setClipboardData = (text) => {
|
||||||
return new Promise((resolve,reject)=>{
|
return new Promise((resolve, reject) => {
|
||||||
uni.setClipboardData({
|
uni.setClipboardData({
|
||||||
data: text,
|
data: text,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
resolve(res)
|
resolve(res);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
reject(err)
|
reject(err);
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统剪贴板内容 uni.getClipboardData
|
* 获取系统剪贴板内容 uni.getClipboardData
|
||||||
|
@ -133,18 +127,18 @@ const setClipboardData = (text) =>{
|
||||||
* 2. 利用async await来接收获取到的数据
|
* 2. 利用async await来接收获取到的数据
|
||||||
* 3. await getClipboardData()
|
* 3. await getClipboardData()
|
||||||
*/
|
*/
|
||||||
const getClipboardData = () =>{
|
const getClipboardData = () => {
|
||||||
return new Promise((resolve,reject)=>{
|
return new Promise((resolve, reject) => {
|
||||||
uni.getClipboardData({
|
uni.getClipboardData({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
resolve(res)
|
resolve(res);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
reject(err)
|
reject(err);
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拨打电话 uni.makePhoneCall()
|
* 拨打电话 uni.makePhoneCall()
|
||||||
|
@ -152,12 +146,11 @@ const getClipboardData = () =>{
|
||||||
* 1. import {getBatteryInfo} from '该文件的地址'
|
* 1. import {getBatteryInfo} from '该文件的地址'
|
||||||
* 2. 直接makePhoneCall(拨打的电话号码)
|
* 2. 直接makePhoneCall(拨打的电话号码)
|
||||||
*/
|
*/
|
||||||
const makePhoneCall = (phone) =>{
|
const makePhoneCall = (phone) => {
|
||||||
uni.makePhoneCall({
|
uni.makePhoneCall({
|
||||||
phoneNumber:phone
|
phoneNumber: phone,
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置缓存
|
* 设置缓存
|
||||||
|
@ -165,7 +158,7 @@ const makePhoneCall = (phone) =>{
|
||||||
* @param {String} data 值
|
* @param {String} data 值
|
||||||
*/
|
*/
|
||||||
export function setStorageSync(key, data) {
|
export function setStorageSync(key, data) {
|
||||||
uni.setStorageSync(key, data)
|
uni.setStorageSync(key, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,7 +166,7 @@ export function setStorageSync(key, data) {
|
||||||
* @param {String} key 键名
|
* @param {String} key 键名
|
||||||
*/
|
*/
|
||||||
export function getStorageSync(key) {
|
export function getStorageSync(key) {
|
||||||
return uni.getStorageSync(key)
|
return uni.getStorageSync(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,7 +174,7 @@ export function getStorageSync(key) {
|
||||||
* @param {String} key 键名
|
* @param {String} key 键名
|
||||||
*/
|
*/
|
||||||
export function removeStorageSync(key) {
|
export function removeStorageSync(key) {
|
||||||
return uni.removeStorageSync(key)
|
return uni.removeStorageSync(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,26 +182,26 @@ export function removeStorageSync(key) {
|
||||||
* @param {String} key 键名
|
* @param {String} key 键名
|
||||||
*/
|
*/
|
||||||
export function clearStorageSync() {
|
export function clearStorageSync() {
|
||||||
return uni.clearStorageSync()
|
return uni.clearStorageSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面跳转
|
* 页面跳转
|
||||||
* @param {'navigateTo' | 'redirectTo' | 'reLaunch' | 'switchTab' | 'navigateBack' | number } url 转跳路径
|
* @param {'navigateTo' | 'redirectTo' | 'reLaunch' | 'switchTab' | 'navigateBack' | number } url 转跳路径
|
||||||
* @param {String} params 跳转时携带的参数
|
* @param {String} params 跳转时携带的参数
|
||||||
* @param {String} type 转跳方式
|
* @param {String} type 转跳方式
|
||||||
**/
|
**/
|
||||||
export function useRouter(url, params = {}, type = 'navigateTo') {
|
export function useRouter(url, params = {}, type = "navigateTo") {
|
||||||
try {
|
try {
|
||||||
if (Object.keys(params).length) url = `${url}?data=${encodeURIComponent(JSON.stringify(params))}`
|
if (Object.keys(params).length)
|
||||||
if (type === 'navigateBack') {
|
url = `${url}?data=${encodeURIComponent(JSON.stringify(params))}`;
|
||||||
uni[type]({ delta: url })
|
if (type === "navigateBack") {
|
||||||
|
uni[type]({ delta: url });
|
||||||
} else {
|
} else {
|
||||||
uni[type]({ url })
|
uni[type]({ url });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,16 +209,19 @@ export function useRouter(url, params = {}, type = 'navigateTo') {
|
||||||
* 预览图片
|
* 预览图片
|
||||||
* @param {Array} urls 图片链接
|
* @param {Array} urls 图片链接
|
||||||
*/
|
*/
|
||||||
export function previewImage(urls, itemList = ['发送给朋友', '保存图片', '收藏']) {
|
export function previewImage(
|
||||||
|
urls,
|
||||||
|
itemList = ["发送给朋友", "保存图片", "收藏"]
|
||||||
|
) {
|
||||||
uni.previewImage({
|
uni.previewImage({
|
||||||
urls,
|
urls,
|
||||||
longPressActions: {
|
longPressActions: {
|
||||||
itemList,
|
itemList,
|
||||||
fail: function (error) {
|
fail: function (error) {
|
||||||
console.error(error,'===previewImage')
|
console.error(error, "===previewImage");
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,86 +229,89 @@ export function previewImage(urls, itemList = ['发送给朋友', '保存图片'
|
||||||
* @param {String} filePath 图片临时路径
|
* @param {String} filePath 图片临时路径
|
||||||
**/
|
**/
|
||||||
export function saveImage(filePath) {
|
export function saveImage(filePath) {
|
||||||
if (!filePath) return false
|
if (!filePath) return false;
|
||||||
uni.saveImageToPhotosAlbum({
|
uni.saveImageToPhotosAlbum({
|
||||||
filePath,
|
filePath,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
toast('图片保存成功', 'success')
|
toast("图片保存成功", "success");
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
if (err.errMsg === 'saveImageToPhotosAlbum:fail:auth denied' || err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
|
if (
|
||||||
|
err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" ||
|
||||||
|
err.errMsg === "saveImageToPhotosAlbum:fail auth deny"
|
||||||
|
) {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: "提示",
|
||||||
content: '需要您授权保存相册',
|
content: "需要您授权保存相册",
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
success: (modalSuccess) => {
|
success: (modalSuccess) => {
|
||||||
uni.openSetting({
|
uni.openSetting({
|
||||||
success(settingdata) {
|
success(settingdata) {
|
||||||
if (settingdata.authSetting['scope.writePhotosAlbum']) {
|
if (settingdata.authSetting["scope.writePhotosAlbum"]) {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: "提示",
|
||||||
content: '获取权限成功,再次点击图片即可保存',
|
content: "获取权限成功,再次点击图片即可保存",
|
||||||
showCancel: false
|
showCancel: false,
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: "提示",
|
||||||
content: '获取权限失败,将无法保存到相册哦~',
|
content: "获取权限失败,将无法保存到相册哦~",
|
||||||
showCancel: false
|
showCancel: false,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail(failData) {
|
fail(failData) {
|
||||||
console.log('failData', failData)
|
console.log("failData", failData);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
}
|
});
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 深拷贝
|
* 深拷贝
|
||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
**/
|
**/
|
||||||
export const clone = (data) => JSON.parse(JSON.stringify(data))
|
export const clone = (data) => JSON.parse(JSON.stringify(data));
|
||||||
/**
|
/**
|
||||||
* 获取平台名称
|
* 获取平台名称
|
||||||
* @return {string} 平台名称
|
* @return {string} 平台名称
|
||||||
*/
|
*/
|
||||||
export function getPlatform() {
|
export function getPlatform() {
|
||||||
let platform;
|
let platform;
|
||||||
switch (process.env.VUE_APP_PLATFORM) {
|
switch (process.env.VUE_APP_PLATFORM) {
|
||||||
case 'app':
|
case "app":
|
||||||
case 'app-plus':
|
case "app-plus":
|
||||||
let n = uni.getSystemInfoSync().platform.toLowerCase();
|
let n = uni.getSystemInfoSync().platform.toLowerCase();
|
||||||
if (n === 'ios') {
|
if (n === "ios") {
|
||||||
platform = 'ios';
|
platform = "ios";
|
||||||
} else if (n === 'android') {
|
} else if (n === "android") {
|
||||||
platform = 'android';
|
platform = "android";
|
||||||
} else {
|
} else {
|
||||||
platform = 'app';
|
platform = "app";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'mp-weixin':
|
case "mp-weixin":
|
||||||
platform = 'wx';
|
platform = "wx";
|
||||||
break;
|
break;
|
||||||
case 'mp-alipay':
|
case "mp-alipay":
|
||||||
platform = 'alipay';
|
platform = "alipay";
|
||||||
break;
|
break;
|
||||||
case 'mp-baidu':
|
case "mp-baidu":
|
||||||
platform = 'baidu';
|
platform = "baidu";
|
||||||
break;
|
break;
|
||||||
case 'mp-qq':
|
case "mp-qq":
|
||||||
platform = 'qq';
|
platform = "qq";
|
||||||
break;
|
break;
|
||||||
case 'mp-toutiao':
|
case "mp-toutiao":
|
||||||
platform = 'toutiao';
|
platform = "toutiao";
|
||||||
break;
|
break;
|
||||||
case 'quickapp-webview':
|
case "quickapp-webview":
|
||||||
platform = 'kuai';
|
platform = "kuai";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +324,9 @@ export function getPlatform() {
|
||||||
* @retrun {Array} 数值
|
* @retrun {Array} 数值
|
||||||
*/
|
*/
|
||||||
export function arrayShuffle(array) {
|
export function arrayShuffle(array) {
|
||||||
let i = array.length, t, j;
|
let i = array.length,
|
||||||
|
t,
|
||||||
|
j;
|
||||||
while (i) {
|
while (i) {
|
||||||
j = Math.floor(Math.random() * i--);
|
j = Math.floor(Math.random() * i--);
|
||||||
t = array[i];
|
t = array[i];
|
||||||
|
@ -341,23 +342,23 @@ export function arrayShuffle(array) {
|
||||||
* @param {string} format 返回的日期格式
|
* @param {string} format 返回的日期格式
|
||||||
* @retrun {string} 日期
|
* @retrun {string} 日期
|
||||||
*/
|
*/
|
||||||
export function dateFormat(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
export function dateFormat(date, format = "YYYY-MM-DD HH:mm:ss") {
|
||||||
const config = {
|
const config = {
|
||||||
YYYY: date.getFullYear(),
|
YYYY: date.getFullYear(),
|
||||||
MM: date.getMonth()+1,
|
MM: date.getMonth() + 1,
|
||||||
DD: date.getDate(),
|
DD: date.getDate(),
|
||||||
HH: date.getHours(),
|
HH: date.getHours(),
|
||||||
mm: date.getMinutes(),
|
mm: date.getMinutes(),
|
||||||
ss: date.getSeconds(),
|
ss: date.getSeconds(),
|
||||||
}
|
};
|
||||||
for(const key in config){
|
for (const key in config) {
|
||||||
let value = config[key];
|
let value = config[key];
|
||||||
if (value < 10) {
|
if (value < 10) {
|
||||||
value = '0' + value;
|
value = "0" + value;
|
||||||
}
|
}
|
||||||
format = format.replace(key, value)
|
format = format.replace(key, value);
|
||||||
}
|
}
|
||||||
return format
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,10 +367,11 @@ export function dateFormat(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||||
* @param {Function} cb 回调
|
* @param {Function} cb 回调
|
||||||
*/
|
*/
|
||||||
export function base64ToSrc(base64data, cb) {
|
export function base64ToSrc(base64data, cb) {
|
||||||
const FILE_BASE_NAME = 'tmp_base64src';
|
const FILE_BASE_NAME = "tmp_base64src";
|
||||||
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
|
const [, format, bodyData] =
|
||||||
|
/data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
|
||||||
if (!format) {
|
if (!format) {
|
||||||
return (new Error('格式错误'));
|
return new Error("格式错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
|
@ -383,10 +385,10 @@ export function base64ToSrc(base64data, cb) {
|
||||||
uni.getFileSystemManager().writeFile({
|
uni.getFileSystemManager().writeFile({
|
||||||
filePath,
|
filePath,
|
||||||
data: buffer,
|
data: buffer,
|
||||||
encoding: 'binary',
|
encoding: "binary",
|
||||||
success() {
|
success() {
|
||||||
cb && cb(filePath);
|
cb && cb(filePath);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +398,7 @@ export function base64ToSrc(base64data, cb) {
|
||||||
* @param {string}
|
* @param {string}
|
||||||
*/
|
*/
|
||||||
export function encodeBase64(str) {
|
export function encodeBase64(str) {
|
||||||
return new Buffer.from(str).toString('base64');
|
return new Buffer.from(str).toString("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -405,8 +407,8 @@ export function encodeBase64(str) {
|
||||||
* @param {string}
|
* @param {string}
|
||||||
*/
|
*/
|
||||||
export function decodeBase64(str) {
|
export function decodeBase64(str) {
|
||||||
const commonContent = str.replace(/\s/g, '+');
|
const commonContent = str.replace(/\s/g, "+");
|
||||||
return new Buffer.from(commonContent, 'base64').toString();
|
return new Buffer.from(commonContent, "base64").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -428,7 +430,7 @@ export function playSound(src, loop = false) {
|
||||||
* @param {string} prefix 订单前缀
|
* @param {string} prefix 订单前缀
|
||||||
* @param {string} 订单ID
|
* @param {string} 订单ID
|
||||||
*/
|
*/
|
||||||
export function createOrderSn(prefix = '') {
|
export function createOrderSn(prefix = "") {
|
||||||
return `${prefix}${this.randomString(10).toUpperCase()}${+new Date()}`;
|
return `${prefix}${this.randomString(10).toUpperCase()}${+new Date()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,35 +443,74 @@ export function imageToBase64(src) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.getImageInfo({
|
uni.getImageInfo({
|
||||||
src,
|
src,
|
||||||
success: image => {
|
success: (image) => {
|
||||||
console.log(image);
|
console.log(image);
|
||||||
uni.getFileSystemManager().readFile({
|
uni.getFileSystemManager().readFile({
|
||||||
filePath: image.path,
|
filePath: image.path,
|
||||||
encoding: 'base64',
|
encoding: "base64",
|
||||||
success: e => {
|
success: (e) => {
|
||||||
return resolve(`data:image/jpeg;base64,${e.data}`);
|
return resolve(`data:image/jpeg;base64,${e.data}`);
|
||||||
},
|
},
|
||||||
fail: e => {
|
fail: (e) => {
|
||||||
return reject(null);
|
return reject(null);
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 随机范围内的数字
|
* 随机范围内的数字
|
||||||
* @param {number} start 起始数字
|
* @param {number} start 起始数字
|
||||||
* @param {number} end 起始数字
|
* @param {number} end 起始数字
|
||||||
* @return {number || null} 随机数
|
* @return {number || null} 随机数
|
||||||
*/
|
*/
|
||||||
export function randomByRange(start, end){
|
export function randomByRange(start, end) {
|
||||||
if (typeof start === 'number' && typeof end === 'number') {
|
if (typeof start === "number" && typeof end === "number") {
|
||||||
return start + Math.floor(Math.random() * (end - start));
|
return start + Math.floor(Math.random() * (end - start));
|
||||||
} else {
|
} else {
|
||||||
console.error('参数必须为数字');
|
console.error("参数必须为数字");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断所给时间和今天的差值
|
||||||
|
* @param {string} date 所给时间
|
||||||
|
* @returns {string} 差值
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function getDateDiff(date) {
|
||||||
|
const inputDate = new Date(date.replace(/\//g, "-"));
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
inputDate.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const timeDiff = inputDate - today;
|
||||||
|
const oneDay = 24 * 60 * 60 * 1000;
|
||||||
|
const daysDiff = Math.floor(timeDiff / oneDay);
|
||||||
|
|
||||||
|
if (daysDiff === 0) {
|
||||||
|
return "今天";
|
||||||
|
} else if (daysDiff > 0) {
|
||||||
|
return `${daysDiff}天后`;
|
||||||
|
} else {
|
||||||
|
return `${Math.abs(daysDiff)}天前`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将分钟转换为时间格式
|
||||||
|
* @param {number} minutes 分钟
|
||||||
|
* @returns {string} 时间格式
|
||||||
|
*/
|
||||||
|
export function minutesToTime(minutes) {
|
||||||
|
const hours = Math.floor(minutes / 60);
|
||||||
|
const mins = minutes % 60;
|
||||||
|
const formattedHours = String(hours).padStart(2, '0');
|
||||||
|
const formattedMins = String(mins).padStart(2, '0');
|
||||||
|
return `${formattedHours}:${formattedMins}`;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue