123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- import { defineStore } from "pinia";
- import config from "@/config";
- import { storage } from "@/utils/storage";
- import modal from "@/plugins/modal.plugins.js";
- import tab from "@/plugins/tab.plugins.js";
- import setting from "@/plugins/setting.plugins.js";
- import { useStores } from "@/store/modules/index";
- import { uploadAvatar, updateUserProfile } from "@/api/system/user";
- import { baseAppInfoApi } from "@/api/common/index";
- import { checkUpdates } from "@/api/system/setting";
- const settingStore = defineStore("storage-setting", {
- state: () => ({
- pushClientId: undefined,//应用消息推送cid
- currentSize: "",//APP缓存
- barHeight: 0,//微信小程序顶部安全距离
- webViewHeight: "",//webView整体高度-铺满
- StatusBar: 0,//APP顶部安全距离
- tabBarHeight: "",//APP底部安全距离
- barHightTop: "",//APP头部计算距离
- themeColor: storage.get("themeColor"),//主题
- fingerprintUserList: storage.get("fingerprintUserList"),//指纹登录用户数据
- nfcWaiting: "请将手机靠近NFC标签", //nfc读取页面-提示文字-数据存储
- }),
- actions: {
- /**
- * @系统主题颜色
- */
- systemThemeColor(type) {
- setTimeout(() => {
- if (type.includes(2)) {
- uni.setTabBarStyle({
- selectedColor: this.themeColor.color,
- borderStyle: "white",
- });
- this.themeColor.tabList.forEach((selectedIconPath, index) => {
- uni.setTabBarItem({
- index,
- selectedIconPath,
- });
- });
- }
- if (type.includes(1)) {
- uni.setNavigationBarColor({
- frontColor: "#ffffff",
- backgroundColor: this.themeColor.color,
- animation: {
- duration: 400,
- timingFunc: "easeIn",
- },
- });
- }
- }, 0);
- },
- /**
- * @动态获取屏幕头部高度
- */
- systemHeightTop() {
- let systemInfo = uni.getSystemInfoSync();
- var statusBarHeight = systemInfo.statusBarHeight
- this.webViewHeight = systemInfo.safeArea.bottom //高度+安全区域的高度
- this.StatusBar = statusBarHeight
- this.tabBarHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom + "px"
- this.barHightTop = this.StatusBar ? this.StatusBar + 44 + 'px' : '44px'
- //#ifdef MP
- let custom = wx.getMenuButtonBoundingClientRect();
- let CustomBar = custom.bottom + custom.top - systemInfo.statusBarHeight;
- this.barHeight = CustomBar || 0
- //#endif
- },
- /**
- * @动态获取用户设备信息
- */
- baseAppInfo() {
- var params = {
- networkType: null, //网络类型
- deviceBrand: null, //设备品牌
- deviceId: null, //设备编号
- deviceModel: null, //设备型号
- userName: null, //用户账号
- longitude: "", //经度
- latitude: "", //纬度
- };
- uni.getNetworkType({
- success: function (res) {
- params.networkType = res.networkType;
- },
- });
- // 获取系统信息
- const systemInfo = uni.getSystemInfoSync();
- params.deviceBrand = systemInfo.deviceBrand;
- params.deviceId = systemInfo.deviceId;
- params.deviceModel = systemInfo.deviceModel;
- params.operateSystem = systemInfo.platform;
- uni.getLocation({
- type: "gcj02",
- geocode: true,
- highAccuracyExpireTime: 5000,
- success: (res) => {
- params.longitude = res.longitude.toString();
- params.latitude = res.latitude.toString();
- baseAppInfoApi(params).then((res) => { })
- },
- fail: (res) => {
- },
- });
- },
- /**
- * @消息推送监听
- */
- pushListener() {
- //获取应用的CID
- uni.getPushClientId({
- success: (res) => {
- this.pushClientId = res.cid
- },
- fail(err) {
- console.log(err);
- },
- });
- const platform = uni.getSystemInfoSync().platform;
- // 接收推送信息 在线
- plus.push.addEventListener("receive", (res) => {
- uni.createPushMessage({
- title: res.title,
- content: res.content,
- });
- });
- // 点击推送信息
- plus.push.addEventListener("click", (res) => {
- console.log(res);
- if (res.aps) {
- if ("url" in res.payload) {
- } else {
- }
- console.log(res.payload);
- }
- });
- },
- /**
- * @点击登录
- */
- handleToLogin() {
- tab.reLaunch("/pages/login");
- },
- /**
- * @点击头像
- */
- handleToAvatar(type) {
- if (type == 1) {
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ["album", "camera"], //从相册选择、摄像头
- success: function (res) {
- this.uploadApi(res);
- },
- });
- } else if (type == 2) {
- tab.navigateTo("/pages/mine/avatar/index");
- }
- },
- /**
- * @upload上传头像
- * @api接口请求
- */
- uploadApi(res) {
- const useStore = useStores();
- let data = { name: "file", filePath: res.tempFilePaths[0] };
- uploadAvatar(data).then((response) => {
- useStore.avatar = response.data.url;
- updateUserProfile({
- avatar: response.data.url,
- }).then(() => { });
- });
- },
- /**
- * @常见问题
- */
- handleHelp() {
- tab.navigateTo("/pages/mine/help/index");
- },
- /**
- * @我的信息
- */
- handleToEditInfo() {
- tab.navigateTo("/pages/mine/info/index");
- },
- /**
- * @关于我们
- */
- handleAbout() {
- tab.navigateTo("/pages/mine/about/index");
- },
- /**
- * @清理缓存
- */
- handleCleanTmp() {
- // #ifdef H5
- uni.showToast({
- title: "缓存清理完成",
- duration: 2000,
- mask: true,
- });
- // #endif
- // #ifdef APP-PLUS
- setting.clearCache();//清除应用访问缓存
- // #endif
- },
- /**
- * @检查更新
- */
- handleToUpgrade({ success, error }) {
- let data = {
- _api_key: "fba7440cd37400b6ff46e303896af4df",
- appKey: "cbd3508235d03365f4253f6aae6b68ab",
- buildVersion: config.appInfo.version,
- };
- modal.loading("加载中");
- checkUpdates(data).then((res) => {
- if (res.code == 0) {
- let platform = uni.getSystemInfoSync().platform; //手机平台
- if (res.data.buildHaveNewVersion == true) {
- //安卓手机弹窗升级
- if (platform === "android") {
- success(res)
- }
- //IOS无法在线升级提示到商店下载
- else {
- uni.showModal({
- title: "发现新版本 " + res.data.buildVersion,
- content: "请到App store进行升级",
- showCancel: false,
- });
- }
- } else {
- modal.msg("您的软件版本已是最新");
- }
- modal.closeLoading();
- }
- });
- },
- /**
- * @新消息通知
- */
- handleToMessage() {
- tab.navigateTo("/pages/mine/msg/index");
- },
- /**
- * @账号与安全
- */
- handleToSecure() {
- tab.navigateTo("/pages/mine/secure/index");
- },
- /**
- * @设置
- */
- handleSetting() {
- tab.navigateTo("/pages/mine/setting/index");
- },
- /**
- * @退出登录
- */
- handleLogout() {
- const useStore = useStores();
- modal.confirm("确定注销并退出系统吗?").then(() => {
- useStore.LogOut().then(() => {
- tab.reLaunch("/pages/index");
- });
- });
- },
- SET_THEMECOLOR(themeColor) {
- this.themeColor = themeColor;
- storage.set("themeColor", themeColor);
- },
- SET_FINGERPRINT(array) {
- this.fingerprintUserList = array;
- storage.set("fingerprintUserList", array);
- }
- },
- });
- export default settingStore;
|