This commit is contained in:
wtq
2026-05-19 17:35:17 +08:00
parent 52a96a3539
commit 1aee989da1
14 changed files with 305 additions and 79 deletions

View File

@@ -2,14 +2,20 @@
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { store } from "./store";
onLaunch(async (query) => {
console.log("App Launch,扫码的参数信息",query);
wx.getLaunchOptionsSync((res:any) => {
console.log('获取本次应用启动的参数信息',res)
})
// wx.getLaunchOptionsSync((res:any) => {
// console.log('获取本次应用启动的参数信息',res)
// })
await store.dispatch('serveInfo/wxLogin',{authType:'wx',isJudg:true}) // 查看当前用户是否为新用户
// console.log('查看当前用户是否为新用户',res)
let userInfo = uni.getStorageSync('userInfo')
// savePromoteInfo(query) // 新用户
if(!userInfo.phoneNumber) savePromoteInfo(query) // 新用户
autoUpdate() // 检查版本更新
});
onShow(() => {
@@ -18,6 +24,69 @@ onShow(() => {
onHide(() => {
console.log("App Hide");
});
/**
* 自动更新版本
*/
function autoUpdate(){
// 获取小程序更新机制兼容
if (uni.canIUse('getUpdateManager')) {
const updateManager = uni.getUpdateManager()
// 检查是否有新版本发布
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
//小程序有新版本,则静默下载新版本,做好更新准备
updateManager.onUpdateReady(function () {
// uni.jxAlert({
// title: '更新提示',
// content: '应用已经升级到新版本了请及时更新',
// success: () => {
// updateManager.applyUpdate()
// }
// })
uni.showModal({
title:'更新提示',
content: '应用已经升级到新版本了请及时更新',
confirmText: '确定',
showCancel: false,
confirmColor: "#51b535",
success: () => {
updateManager.applyUpdate()
}
})
})
// 新的版本下载失败
updateManager.onUpdateFailed(function () {
uni.showModal({
title: '温馨提示',
content: '新版本已经上线,请您删除当前小程序,重新搜索打开',
})
})
}
})
} else {
// 提示用户在最新版本的客户端上体验
uni.showModal({
title: '温馨提示',
content: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
})
}
}
/**
* 是否保存推荐信息
*/
function savePromoteInfo(query:any){
if(query?.scene && query.scene === 1047){
// 扫描小程序码进入
if(query.query){
console.log(query,"App Launch,扫码的参数信息",query?.query);
const encodedStr = decodeURIComponent(query.query.scene); // 编码单个参数
console.log('encodedStr',encodedStr)
uni.setStorageSync('promotionSource',encodedStr.slice(8))
}
}
}
</script>
<style>
@import './static/font/iconfont.css';

View File

@@ -101,7 +101,7 @@ const login = {
},
/**
/**
* 注册和修改密码
* Password string `p:"password"` // 密码
* OldPassword string `p:"old_password"` // 旧密码

View File

@@ -89,7 +89,6 @@ const order = {
del_qiniu_img : async (imgs:string) => {
return await request.api('/jx_horizon/wechat/deleteQiNiuImg', 'POST',{imgs})
}
// https://jxhorizon.jxc4.com/jx_horizon/wechat/DeleteQiNiuImg deleteQiNiuImg
}

View File

@@ -9,7 +9,8 @@ import { getStorage } from "@/utils/storage";
import { store } from "@/store";
import { addTask, jx_trembling } from "@/utils/tools";
// import configCms from "@/utils/configCms";
// import log from '@/utils/log'
import log from '@/utils/log'
import configCms from "@/utils/configCms";
// 定义请求类型
@@ -70,32 +71,33 @@ const request: Api = {
timeout: timeout,
header: {
'content-type': contentType,
'Authorization': getStorage('token') ? getStorage('token') : 'jxcs'
// && store.getters['serveInfo/isLogin']
'Authorization': !configCms.whiteListUrl.includes(url) ? getStorage('token') ? getStorage('token') : '' : ''
},
success: (res) => {
//#region
// let logData = {
// '日志记录时间': Date(),
// '调用接口': url,
// '请求方法': method,
// '请求参数': data,
// '请求超时时间': timeout,
// '请求域名': baseURL,
// '登录类型': getStorage('loginType') ? getStorage('loginType') : '未获取到用户登录类型',
// '用户TOKEN': getStorage('token') ? getStorage('token') : '未获取到用户TOKEN',
// '权限ID': getStorage('userType') ? getStorage('userType') : '未获取到用户权限ID',
// '用户ID': getStorage('userID') ? getStorage('userID') : '未获取到用户ID',
// '用户ID2': getStorage('userID2') ? getStorage('userID2') : '未获取到用户ID2',
// '用户手机号': getStorage('mobile') ? getStorage('mobile') : '未获取到用户手机号',
// '店铺ID': getStorage('storeID') ? getStorage('storeID') : '未获取到店铺ID',
// '店铺名字': getStorage('storeName') ? getStorage('storeName') : '未获取到店铺名字',
// '网络状态码': res.statusCode,
// '服务端数据': res.data
// }
let logData = {
'日志记录时间': Date(),
'调用接口': url,
'请求方法': method,
'请求参数': data,
'请求超时时间': timeout,
'请求域名': baseURL,
'登录类型': getStorage('loginType') ? getStorage('loginType') : '未获取到用户登录类型',
'用户TOKEN': getStorage('token') ? getStorage('token') : '未获取到用户TOKEN',
// '权限ID': getStorage('userType') ? getStorage('userType') : '未获取到用户权限ID',
// '用户ID': getStorage('userID') ? getStorage('userID') : '未获取到用户ID',
// '用户ID2': getStorage('userID2') ? getStorage('userID2') : '未获取到用户ID2',
'用户手机号': getStorage('mobile') ? getStorage('mobile') : '未获取到用户手机号',
// '店铺ID': getStorage('storeID') ? getStorage('storeID') : '未获取到店铺ID',
// '店铺名字': getStorage('storeName') ? getStorage('storeName') : '未获取到店铺名字',
'网络状态码': res.statusCode,
'服务端数据': res.data
}
//#endregion
// store.commit('storeInfo/jxLoadingFn', false) // 关闭自定义加载图vuex)
if (res.statusCode >= 200 && res.statusCode < 300) {
// log.info(JSON.stringify(logData))
log.info(JSON.stringify(logData))
// 通过token 验证 通过store 验证
if ((res.data as AnyObject).code == '-2') {
// uni.jxAlert({
@@ -122,15 +124,15 @@ const request: Api = {
}
}
} else if (res.statusCode >= 400 && res.statusCode < 500) {
// log.warn(JSON.stringify(logData))
log.warn(JSON.stringify(logData))
toast('客户端出错', 2)
reject('客户端出错')
} else if (res.statusCode >= 500) {
// log.warn(JSON.stringify(logData))
log.warn(JSON.stringify(logData))
toast('服务端出错', 2)
reject('服务端出错')
} else {
// log.warn(JSON.stringify(logData))
log.warn(JSON.stringify(logData))
toast('网络请求出错', 2)
}
},
@@ -143,24 +145,24 @@ const request: Api = {
console.log('jx-网络请求超时', error);
reject(`网络请求超时 -- request.ts, ${error}`)
//#region
// let logData = {
// '日志记录时间': Date(),
// '调用接口': url,
// '请求方法': method,
// '请求参数': data,
// '请求超时时间': timeout,
// '请求域名': baseURL,
// '登录类型': getStorage('loginType') ? getStorage('loginType') : '未获取到用户登录类型',
// '用户TOKEN': getStorage('token') ? getStorage('token') : '未获取到用户TOKEN',
// '权限ID': getStorage('userType') ? getStorage('userType') : '未获取到用户权限ID',
// '用户ID': getStorage('userID') ? getStorage('userID') : '未获取到用户ID',
// '用户ID2': getStorage('userID2') ? getStorage('userID2') : '未获取到用户ID2',
// '用户手机号': getStorage('mobile') ? getStorage('mobile') : '未获取到用户手机号',
// '店铺ID': getStorage('storeID') ? getStorage('storeID') : '未获取到店铺ID',
// '店铺名字': getStorage('storeName') ? getStorage('storeName') : '未获取到店铺名字',
// '请求错误信息': error
// }
// log.error(JSON.stringify(logData)) // 普通请求日志
let logData = {
'日志记录时间': Date(),
'调用接口': url,
'请求方法': method,
'请求参数': data,
'请求超时时间': timeout,
'请求域名': baseURL,
'登录类型': getStorage('loginType') ? getStorage('loginType') : '未获取到用户登录类型',
'用户TOKEN': getStorage('token') ? getStorage('token') : '未获取到用户TOKEN',
// '权限ID': getStorage('userType') ? getStorage('userType') : '未获取到用户权限ID',
// '用户ID': getStorage('userID') ? getStorage('userID') : '未获取到用户ID',
// '用户ID2': getStorage('userID2') ? getStorage('userID2') : '未获取到用户ID2',
'用户手机号': getStorage('mobile') ? getStorage('mobile') : '未获取到用户手机号',
// '店铺ID': getStorage('storeID') ? getStorage('storeID') : '未获取到店铺ID',
// '店铺名字': getStorage('storeName') ? getStorage('storeName') : '未获取到店铺名字',
'请求错误信息': error
}
log.error(JSON.stringify(logData)) // 普通请求日志
//#endregion
},
complete: () => {

View File

@@ -102,6 +102,52 @@ function useGlobalFunc() {
}
/**
* 保存图片
*/
// 保存网络图片到相册(正式版可用)
async function saveImageToAlbum(imgUrl:string) {
try {
// 1. 申请相册权限
const authRes = await uni.authorize({
scope: 'scope.writePhotosAlbum'
}).catch(() => null);
console.log('相册权限的返回值',authRes)
if (!authRes) {
uni.showModal({
title: '权限提示',
content: '需要相册权限才能保存图片,请在设置中开启',
success(res) {
if (res.confirm) uni.openSetting();
}
});
return;
}
// 2. 先下载到本地临时路径关键不能直接传url
const downRes = await uni.downloadFile({
url: imgUrl
});
if (downRes.statusCode !== 200) {
uni.showToast({ title: '图片下载失败', icon: 'none' });
return;
}
// 3. 保存到相册
await uni.saveImageToPhotosAlbum({
filePath: downRes.tempFilePath
});
uni.showToast({ title: '保存成功' });
} catch (err) {
console.error('保存失败:', err);
uni.showToast({ title: '保存失败', icon: 'none' });
}
}
/*************************************************
* 存储用户信息
* @param {object} [data] 用户信息数据
@@ -589,6 +635,7 @@ function useGlobalFunc() {
return {
// globGetToDay, //获取实时订单数据
saveImageToAlbum, // 保存图片
previewImage, // 查看详情图
setUserInfo, // 储存用户信息
// newMessage, // 展示新信息

View File

@@ -296,8 +296,9 @@ function closeDrawer(){
* 退出登录
*/
function exitLogin(){
uni.clearStorage()
uni.clearStorageSync()
store.commit('serveInfo/changeLoginStatus',false)
store.dispatch('serveInfo/wxLogin',{authType:'wx',isJudg:true}) // 查看当前用户是否为新用户
}
/**
@@ -369,7 +370,7 @@ async function getAccountInvoice(){
content:'嘿,好久不见,甚是想念。',
}]
try {
// if(!isLogin.value) return
if(!isLogin.value) return
let time = new Date()
let obj = {
rank:'desc', // desc/asc
@@ -465,6 +466,7 @@ async function sendText(){
if(url) obj.image = url // 多张图,逗号隔开
// console.log('中间的菜篮,,参数',obj)
// return
keyWord.value = '' // 清除输入框的内容
let res = await order.useText2Msg(obj)
toast('发送成功,请等待......')
if(res.code == 0){
@@ -485,7 +487,6 @@ async function sendText(){
scrollToView.value = 'msg' + (historyList.value.length -1)
console.log(historyList.value,'打印返回图片的信息',res)
isLoadingImg.value = false
keyWord.value = ''
delImg(url)
// getAccountInvoice
}else{

View File

@@ -17,7 +17,7 @@ export default {
*/
wxLogin:async (store:any,{authType = 'wx',isJudg = false,obj = {}}) => {
store.commit('changeLoginStatus',false) // 重置登录状态
let data = {}
let data:AnyObject = {}
if(authType == 'wx'){
// 微信登录
let getCode = await login.get_jx_code(isJudg);
@@ -29,6 +29,12 @@ export default {
// 账号密码登录 或 验证码登录
data = obj
}
let promotionSource = uni.getStorageSync('promotionSource')
if(promotionSource){
data.promotionSource = uni.getStorageSync('promotionSource')
uni.removeStorageSync('promotionSource');
}
console.log('登录的参数信息',data)
let res = await login.applets_login(data,isJudg);

View File

@@ -215,6 +215,7 @@ async function pwdLogin() {
async function getPhoneNum(e:AnyObject){
console.log('获取手机号',e.detail)
let userInfo = uni.getStorageSync('userInfo')
if(!uni.getStorageSync('token')) await store.dispatch('serveInfo/wxLogin',{authType:'wx',isJudg:true}) // 查看当前用户是否为新用户
if(e.detail.errMsg === 'getPhoneNumber:ok'){
let res = await login.decryUser({
sessionKey:userInfo.session_key,
@@ -222,10 +223,12 @@ async function getPhoneNum(e:AnyObject){
encryptedData:e.detail.encryptedData,
type:'phone'
})
if(res.data == 0){
if(res.code == 0){
// 绑定成功
// setUserInfo(res.data)
uni.navigateTo({ url: '/pages/index/index' })
await store.dispatch('serveInfo/wxLogin',{authType:'wx'}) // 刷新登录信息
}else{
toast('绑定手机号失败')
}
}
}

View File

@@ -125,17 +125,18 @@ async function changePass(){
}
if(userInfo.value.userId2 ? userName.value !== userInfo.value.userId2 : userName.value !== mobile.value) data.userName = userName.value
if(JSON.stringify(data) === '{}') return toast('没有要修改的信息')
console.log('修改密码的参数信息',data)
// console.log('修改密码的参数信息',data)
let res = await login.changePassword(data)
console.log('设置密码,成功了没',res)
// console.log('设置密码,成功了没',res)
if(res.code == 0){
toast('修改成功')
let userInfoNew = JSON.parse(JSON.stringify(userInfo.value))
console.log(userInfoNew,'用户信息',userInfoNew)
// console.log(userInfoNew,'用户信息',userInfoNew)
userInfoNew.userId2 = userName.value
// if(userInfo.value.userId2 ? userName.value !== userInfo.value.userId2 : userName.value !== mobile.value)
uni.setStorageSync('userInfo',userInfoNew)
uni.navigateTo({url:'/pages/index/index'})
// await store.dispatch('serveInfo/wxLogin',{authType:'wx',isJudg:false}) // 查看当前用户是否为新用户
}else toast('修改失败')
} catch (error) {

View File

@@ -14,6 +14,11 @@ import toast from '@/utils/toast'
import { errToast, modal } from '@/utils/uniApi'
import { onShow } from '@dcloudio/uni-app'
import { computed, ref } from 'vue'
import useGlobalFunc from '@/composables/useGlobalFunc'
const {
saveImageToAlbum, // 预览图片
} = useGlobalFunc()
const imgUrl = ref('')
@@ -63,26 +68,68 @@ async function reqGetWxcode(){
*/
async function downloadCode(){
console.log('保存推广码-------',imgUrl.value)
// const [err, res] = await uni.downloadFile({ url: imgUrl.value })
uni.downloadFile({
url: imgUrl.value,
complete(res){
console.log('下载图片成功的方法',res)
if(res.statusCode == 200){
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
complete(r) {
console.log('1111111111,保存商品图片',r)
if (r.errMsg === 'saveImageToPhotosAlbum:ok') {
toast('保存成功')
} else {
toast('保存失败')
}
}
})
}
// const [err, res] = await uni.downloadFile({ url: imgUrl.value })
// uni.downloadFile({
// url: imgUrl.value,
// complete(res){
// console.log('下载图片成功的方法',res)
// if(res.statusCode == 200){
// uni.saveImageToPhotosAlbum({
// filePath: res.tempFilePath,
// complete(r) {
// console.log('1111111111,保存商品图片',r)
// if (r.errMsg === 'saveImageToPhotosAlbum:ok') {
// toast('保存成功')
// } else {
// toast('保存失败')
// }
// }
// })
// }
}
})
// }
// })
saveImageToAlbum(imgUrl.value)
}
// // 保存网络图片到相册(正式版可用)
// async function saveImageToAlbum(imgUrl:string) {
// try {
// // 1. 申请相册权限
// const authRes = await uni.authorize({
// scope: 'scope.writePhotosAlbum'
// }).catch(() => null);
// if (!authRes) {
// uni.showModal({
// title: '权限提示',
// content: '需要相册权限才能保存图片,请在设置中开启',
// success(res) {
// if (res.confirm) uni.openSetting();
// }
// });
// return;
// }
// // 2. 先下载到本地临时路径关键不能直接传url
// const downRes = await uni.downloadFile({
// url: imgUrl
// });
// if (downRes.statusCode !== 200) {
// uni.showToast({ title: '图片下载失败', icon: 'none' });
// return;
// }
// // 3. 保存到相册
// await uni.saveImageToPhotosAlbum({
// filePath: downRes.tempFilePath
// });
// uni.showToast({ title: '保存成功' });
// } catch (err) {
// console.error('保存失败:', err);
// uni.showToast({ title: '保存失败', icon: 'none' });
// }
// }
</script>

View File

@@ -168,10 +168,13 @@ async function surePay(row:AnyObject){
if(payInfo.code == 0){
// ayInfo.data.weChatPay prepayID
await handleCreatePay(payInfo.data)
}else{
toast('支付参数错误')
}
// console.log('打印支付信息',payInfo)
toast('支付成功')
}
}
// 支付相关
@@ -189,8 +192,18 @@ async function handleCreatePay( payInfo:AnyObject){
package:packageA,
signType:'RSA', // MD5 RSA
paySign:paySign,
async success(res:any){
// console.log('充值成功',res)
toast('支付成功')
await store.dispatch('serveInfo/queryAccount') // 充值成功后,查询账户余额,查询账余额
uni.navigateTo({url:'/pages/index/index'})
},
fail(){
toast('支付失败')
},
complete(res:any){
console.log('掉起支付的数据',res)
}
})
}

5
src/utils/configCms.ts Normal file
View File

@@ -0,0 +1,5 @@
export default {
whiteListUrl:[
'/jx_horizon/wechat/login'
]
}

32
src/utils/log.js Normal file
View File

@@ -0,0 +1,32 @@
var log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null
const LOG = {
debug() {
if (!log) return
log.debug.apply(log, arguments)
},
info() {
if (!log) return
log.info.apply(log, arguments)
},
warn() {
if (!log) return
log.warn.apply(log, arguments)
},
error() {
if (!log) return
log.error.apply(log, arguments)
},
setFilterMsg(msg) { // 从基础库2.7.3开始支持
if (!log || !log.setFilterMsg) return
if (typeof msg !== 'string') return
log.setFilterMsg(msg)
},
addFilterMsg(msg) { // 从基础库2.8.1开始支持
if (!log || !log.addFilterMsg) return
if (typeof msg !== 'string') return
log.addFilterMsg(msg)
}
}
export default LOG

View File

@@ -35,6 +35,7 @@
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"src/utils/log.js",
// "src/pages/merchant/index.scss",
// "src/subPages/login/bgImg.js"
]