12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- export const formatTime = (date: Date) => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return (
- [year, month, day].map(formatNumber).join('/') +
- ' ' +
- [hour, minute, second].map(formatNumber).join(':')
- )
- }
- const formatNumber = (n: number) => {
- const s = n.toString()
- return s[1] ? s : '0' + s
- }
- export function errHttp(msg: string) {
- wx.showToast({
- title: msg || "请稍后在试!",
- icon: "error",
- duration: 2000
- })
- }
- export function compareVersion(v1Text: string, v2Text: string): number {
- const v1 = v1Text.split('.')
- const v2 = v2Text.split('.')
- let out = 0;
- const len = Math.max(v1.length, v2.length)
- while (v1.length < len) {
- v1.push('0')
- }
- while (v2.length < len) {
- v2.push('0')
- }
- for (let i = 0; i < len; i++) {
- const num1 = parseInt(v1[i])
- const num2 = parseInt(v2[i])
- if (num1 > num2) {
- out = 1;
- break
- } else if (num1 < num2) {
- out = -1;
- break
- }
- }
- if (out === -1) {
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
- })
- }
- return out
- }
|