提交app
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const debug = false // true 是连地服务端本地,false 是连接线上
|
||||
const debug = true // true 是连地服务端本地,false 是连接线上
|
||||
|
||||
const development = {
|
||||
domain: 'http://192.168.1.62:10215',
|
||||
domain: 'http://192.168.2.126:10215',
|
||||
}
|
||||
|
||||
const production = {
|
||||
|
||||
@@ -1,92 +1,98 @@
|
||||
export default {
|
||||
onPullDownRefresh() {
|
||||
this.store && this.store.reload()
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.store.status != 'noMore') {
|
||||
this.store.next && this.store.next()
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
store: {},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
DataSource(url) {
|
||||
var me = this
|
||||
return {
|
||||
data: [],
|
||||
status: 'noMore',
|
||||
empty: false,
|
||||
total: 0,
|
||||
header: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
params: {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
},
|
||||
timer: null,
|
||||
callBack: null,
|
||||
firstCallBack: null,
|
||||
loadedCallback: null,
|
||||
reload() {
|
||||
if (this.status == 'loading') return
|
||||
this.data = []
|
||||
this.empty = false
|
||||
this.params.pageNum = 1
|
||||
this.next()
|
||||
},
|
||||
search() {
|
||||
// 节流搜索
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => {
|
||||
this.reload()
|
||||
}, 300)
|
||||
},
|
||||
next() {
|
||||
this.status = 'loading'
|
||||
me.$request({
|
||||
url: url,
|
||||
data: this.params,
|
||||
header: this.header,
|
||||
method: 'POST',
|
||||
debounce: false,
|
||||
}).then((res) => {
|
||||
console.warn(res)
|
||||
let resultData = res.data?.list || res.data?.records || res.data || []
|
||||
if (this.params.pageNum == 1) {
|
||||
this.data = resultData
|
||||
if (resultData.length == 0 || resultData == 0) {
|
||||
this.empty = true
|
||||
this.status = 'noMore'
|
||||
} else if (resultData.length < this.params.pageSize) {
|
||||
this.status = 'noMore'
|
||||
} else if (res.total == resultData.length) {
|
||||
this.status = 'noMore'
|
||||
} else {
|
||||
this.status = 'more'
|
||||
}
|
||||
} else {
|
||||
this.data.push(...resultData)
|
||||
if (resultData.length < this.params.pageSize) {
|
||||
this.status = 'noMore'
|
||||
} else {
|
||||
this.status = 'more'
|
||||
}
|
||||
}
|
||||
if (this.params.pageNum == 1) {
|
||||
this.firstCallBack && this.firstCallBack()
|
||||
}
|
||||
this.loadedCallback && this.loadedCallback()
|
||||
this.params.pageNum++
|
||||
this.total = res.total
|
||||
this.loading = false
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
export default {
|
||||
onPullDownRefresh() {
|
||||
if (this.store.isListAtTop) {
|
||||
this.store && this.store.reload()
|
||||
}
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.store.status != 'noMore') {
|
||||
this.store.next && this.store.next()
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
store: {},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
DataSource(url) {
|
||||
var me = this
|
||||
return {
|
||||
data: [],
|
||||
copyData: {},
|
||||
status: 'noMore',
|
||||
empty: false,
|
||||
isListAtTop: true,
|
||||
total: 0,
|
||||
header: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
params: {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
},
|
||||
timer: null,
|
||||
callBack: null,
|
||||
firstCallBack: null,
|
||||
loadedCallback: null,
|
||||
reload() {
|
||||
if (this.status == 'loading') return
|
||||
this.data = []
|
||||
this.empty = false
|
||||
this.params.pageNum = 1
|
||||
this.next()
|
||||
},
|
||||
search() {
|
||||
// 节流搜索
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => {
|
||||
this.reload()
|
||||
}, 300)
|
||||
},
|
||||
next() {
|
||||
this.status = 'loading'
|
||||
me.$request({
|
||||
url: url,
|
||||
data: this.params,
|
||||
header: this.header,
|
||||
method: 'POST',
|
||||
debounce: false,
|
||||
}).then((res) => {
|
||||
console.warn(res)
|
||||
let resultData = res.data?.list || res.data?.records || res.data || []
|
||||
this.copyData = res.data
|
||||
if (this.params.pageNum == 1) {
|
||||
this.data = resultData
|
||||
if (resultData.length == 0 || resultData == 0) {
|
||||
this.empty = true
|
||||
this.status = 'noMore'
|
||||
} else if (resultData.length < this.params.pageSize) {
|
||||
this.status = 'noMore'
|
||||
} else if (res.total == resultData.length) {
|
||||
this.status = 'noMore'
|
||||
} else {
|
||||
this.status = 'more'
|
||||
}
|
||||
} else {
|
||||
this.data.push(...resultData)
|
||||
if (resultData.length < this.params.pageSize) {
|
||||
this.status = 'noMore'
|
||||
} else {
|
||||
this.status = 'more'
|
||||
}
|
||||
}
|
||||
if (this.params.pageNum == 1) {
|
||||
this.firstCallBack && this.firstCallBack()
|
||||
}
|
||||
this.loadedCallback && this.loadedCallback()
|
||||
this.params.pageNum++
|
||||
this.total = res.total || res.data?.total
|
||||
|
||||
this.loading = false
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const MQTT_IP = 'pqmcn.com:8085/mqtt'//mqtt地址端口, 使用emqx时一定要加mqtt
|
||||
// export const MQTT_IP = '192.168.1.24:8085/mqtt'//mqtt地址端口, 使用emqx时一定要加mqtt
|
||||
// export const MQTT_IP = 'pqmcn.com:8085/mqtt'//mqtt地址端口, 使用emqx时一定要加mqtt
|
||||
export const MQTT_IP = '192.168.1.103:8083/mqtt'//mqtt地址端口, 使用emqx时一定要加mqtt
|
||||
|
||||
const MQTT_USERNAME = 't_user'//mqtt用户名
|
||||
const MQTT_PASSWORD = 'njcnpqs'//密码
|
||||
|
||||
@@ -39,7 +39,7 @@ export default (options = {}) => {
|
||||
},
|
||||
method: options.method || 'GET',
|
||||
success: async (res) => {
|
||||
console.log(res)
|
||||
// console.log(res)
|
||||
if (arr.indexOf(options.url) > -1) {
|
||||
setTimeout(() => {
|
||||
arr.splice(arr.indexOf(options.url), 1)
|
||||
|
||||
@@ -107,39 +107,61 @@ function formatTime(time, option) {
|
||||
}
|
||||
// 获取当天日期(年月日)
|
||||
function getToday() {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需+1
|
||||
const day = String(today.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
const today = new Date()
|
||||
const year = today.getFullYear()
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0') // 月份从0开始,需+1
|
||||
const day = String(today.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
// 获取当天日期 往前推30天
|
||||
function getBeforeDays(days = 30) {
|
||||
const today = new Date();
|
||||
// 计算往前推N天的时间戳(1天=86400000毫秒)
|
||||
const beforeDate = new Date(today.getTime() - days * 24 * 60 * 60 * 1000);
|
||||
return formatDate(beforeDate);
|
||||
const today = new Date()
|
||||
// 计算往前推N天的时间戳(1天=86400000毫秒)
|
||||
const beforeDate = new Date(today.getTime() - days * 24 * 60 * 60 * 1000)
|
||||
return formatDate(beforeDate)
|
||||
}
|
||||
function formatDate(date) {
|
||||
const year = date.getFullYear();
|
||||
// 月份从0开始,补零到2位
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
// 日期补零到2位
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
const year = date.getFullYear()
|
||||
// 月份从0开始,补零到2位
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
// 日期补零到2位
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
// 获取3个月前的日期
|
||||
function getThreeMonthsAgo() {
|
||||
const threeMonthsAgo = new Date();
|
||||
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3); // 月份减3
|
||||
const year = threeMonthsAgo.getFullYear();
|
||||
const month = String(threeMonthsAgo.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(threeMonthsAgo.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
const threeMonthsAgo = new Date()
|
||||
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3) // 月份减3
|
||||
const year = threeMonthsAgo.getFullYear()
|
||||
const month = String(threeMonthsAgo.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(threeMonthsAgo.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
//获取月最后一天
|
||||
function getMonthFirstAndLastDay(monthStr) {
|
||||
// 1. 校验输入格式(正则匹配YYYY-MM)
|
||||
const reg = /^\d{4}-\d{2}$/
|
||||
if (!reg.test(monthStr)) {
|
||||
throw new Error('输入格式错误,请传入"YYYY-MM"格式的字符串,例如:2026-03')
|
||||
}
|
||||
|
||||
// 2. 拆分年、月
|
||||
const [year, month] = monthStr.split('-').map(Number)
|
||||
|
||||
// 3. 生成当月第一天(直接拼接01)
|
||||
const firstDay = `${year}-${String(month).padStart(2, '0')}-01`
|
||||
|
||||
// 4. 生成当月最后一天(核心:利用Date的特性,下个月0号 = 当月最后一天)
|
||||
// 注意:月份是0开始的(0=1月,11=12月),所以month+1是下一个月
|
||||
const lastDayDate = new Date(year, month, 0) // 下个月0号 = 当月最后一天
|
||||
const lastDay = `${year}-${String(month).padStart(2, '0')}-${String(lastDayDate.getDate()).padStart(2, '0')}`
|
||||
|
||||
return {
|
||||
firstDay,
|
||||
lastDay,
|
||||
}
|
||||
}
|
||||
|
||||
const h5Helper = {
|
||||
isAndroid: function () {
|
||||
@@ -167,7 +189,7 @@ const getUserLocation = (call) => {
|
||||
success: function (address) {
|
||||
call(address)
|
||||
},
|
||||
fail: (err) => {
|
||||
fail: (err) => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '定位失败,请打开定位权限',
|
||||
@@ -309,12 +331,14 @@ const getDictData = (key) => {
|
||||
resolve(dictData.filter((item) => item.code === key)[0]?.children || [])
|
||||
} else {
|
||||
// 查询字典
|
||||
queryDictDataCache().then((res) => {
|
||||
uni.setStorageSync(cacheKey.dictData, res.data)
|
||||
resolve(res.data.filter((item) => item.code === key)[0]?.children || [])
|
||||
}).catch(err=>{
|
||||
reject(err)
|
||||
})
|
||||
queryDictDataCache()
|
||||
.then((res) => {
|
||||
uni.setStorageSync(cacheKey.dictData, res.data)
|
||||
resolve(res.data.filter((item) => item.code === key)[0]?.children || [])
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -333,5 +357,6 @@ export default {
|
||||
getDictData,
|
||||
getToday,
|
||||
getBeforeDays,
|
||||
getThreeMonthsAgo
|
||||
getThreeMonthsAgo,
|
||||
getMonthFirstAndLastDay,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user