123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- import { defineStore } from "pinia";
- import storage from "@/utils/storage";
- import constant from "@/utils/constant";
- 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";
- const settingStore = defineStore("setting", {
- state: () => ({
- currentSize: "",//APP缓存
- themeColor: storage.get(constant.themeColor),//主题
- barHeight: 0,//微信小程序顶部安全距离
- StatusBar: 0,//app顶部安全距离
- tabBarHeight: 0,//app底部安全距离
- barHightTop: "",//app头部计算距离
- }),
- persist: {
- // 自定义数据持久化方式
- // key: 'store-key', 指定key进行存储,此时非key的值不会持久化,刷新就会丢失
- storage: window ? window.localStorage : uni.setStorageSync(), // 指定换成地址
- // paths: ['nested.data'],// 指定需要持久化的state的路径名称
- beforeRestore: (context) => {
- console.log("Before" + context);
- },
- afterRestore: (context) => {
- console.log("After" + context);
- },
- },
- actions: {
- /**
- * @系统主题颜色
- */
- systemThemeColor(type) {
- 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",
- },
- });
- }
- },
- /**
- * @动态获取屏幕头部高度
- */
- systemHeightTop() {
- let systemInfo = uni.getSystemInfoSync();
- var statusBarHeight = systemInfo.statusBarHeight
- this.StatusBar = statusBarHeight
- this.tabBarHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom
- 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
- },
- /**
- * @常见问题
- */
- handleHelp() {
- tab.navigateTo("/pages/mine/help/index");
- },
- /**
- * @我的信息
- */
- handleToEditInfo() {
- tab.navigateTo("/pages/mine/info/index");
- },
- /**
- * @关于我们
- */
- handleAbout() {
- tab.navigateTo("/pages/mine/about/index");
- },
- /**
- * @清理缓存
- */
- handleCleanTmp() {
- // #ifdef H5
- modal.showToast("H5暂不支持此功能");
- // #endif
- // #ifdef APP-PLUS
- setting.clearCache();
- // #endif
- },
- /**
- * @检查更新
- */
- handleToUpgrade() {
- modal.showToast("模块建设中~");
- },
- /**
- * @账号与安全
- */
- 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");
- });
- });
- },
- /**
- * @点击头像
- */
- 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.$state.avatar = response.data.url;
- updateUserProfile({
- avatar: response.data.url,
- }).then(() => { });
- });
- },
- SET_THEMECOLOR(themeColor) {
- // storage.get(constant.name)
- this.themeColor = themeColor;
- storage.set(constant.themeColor, themeColor);
- },
- },
- });
- export default settingStore;
|