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,
- currentSize: "",
- barHeight: 0,
- webViewHeight: "",
- StatusBar: 0,
- tabBarHeight: "",
- barHightTop: "",
- themeColor: storage.get("themeColor"),
- fingerprintUserList: storage.get("fingerprintUserList"),
- nfcWaiting: "请将手机靠近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'
-
- let custom = wx.getMenuButtonBoundingClientRect();
- let CustomBar = custom.bottom + custom.top - systemInfo.statusBarHeight;
- this.barHeight = CustomBar || 0
-
- },
-
- 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() {
-
- 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,
- sizeType: ["original", "compressed"],
- sourceType: ["album", "camera"],
- success: function (res) {
- this.uploadApi(res);
- },
- });
- } else if (type == 2) {
- tab.navigateTo("/pages/mine/avatar/index");
- }
- },
-
- 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() {
-
- uni.showToast({
- title: "缓存清理完成",
- duration: 2000,
- mask: true,
- });
-
-
- setting.clearCache();
-
- },
-
- 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)
- }
-
- 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;
|