setting.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. import { defineStore } from "pinia";
  2. import config from "@/config";
  3. import { storage } from "@/utils/storage";
  4. import modal from "@/plugins/modal.plugins.js";
  5. import tab from "@/plugins/tab.plugins.js";
  6. import setting from "@/plugins/setting.plugins.js";
  7. import { useStores } from "@/store/modules/index";
  8. import { uploadAvatar, updateUserProfile } from "@/api/system/user";
  9. import { baseAppInfoApi } from "@/api/common/index";
  10. import { checkUpdates } from "@/api/system/setting";
  11. const settingStore = defineStore("storage-setting", {
  12. state: () => ({
  13. pushClientId: undefined,//应用消息推送cid
  14. currentSize: "",//APP缓存
  15. barHeight: 0,//微信小程序顶部安全距离
  16. webViewHeight: "",//webView整体高度-铺满
  17. StatusBar: 0,//APP顶部安全距离
  18. tabBarHeight: "",//APP底部安全距离
  19. barHightTop: "",//APP头部计算距离
  20. themeColor: storage.get("themeColor"),//主题
  21. fingerprintUserList: storage.get("fingerprintUserList"),//指纹登录用户数据
  22. nfcWaiting: "请将手机靠近NFC标签", //nfc读取页面-提示文字-数据存储
  23. }),
  24. actions: {
  25. /**
  26. * @系统主题颜色
  27. */
  28. systemThemeColor(type) {
  29. setTimeout(() => {
  30. if (type.includes(2)) {
  31. uni.setTabBarStyle({
  32. selectedColor: this.themeColor.color,
  33. borderStyle: "white",
  34. });
  35. this.themeColor.tabList.forEach((selectedIconPath, index) => {
  36. uni.setTabBarItem({
  37. index,
  38. selectedIconPath,
  39. });
  40. });
  41. }
  42. if (type.includes(1)) {
  43. uni.setNavigationBarColor({
  44. frontColor: "#ffffff",
  45. backgroundColor: this.themeColor.color,
  46. animation: {
  47. duration: 400,
  48. timingFunc: "easeIn",
  49. },
  50. });
  51. }
  52. }, 0);
  53. },
  54. /**
  55. * @动态获取屏幕头部高度
  56. */
  57. systemHeightTop() {
  58. let systemInfo = uni.getSystemInfoSync();
  59. var statusBarHeight = systemInfo.statusBarHeight
  60. this.webViewHeight = systemInfo.safeArea.bottom //高度+安全区域的高度
  61. this.StatusBar = statusBarHeight
  62. this.tabBarHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom + "px"
  63. this.barHightTop = this.StatusBar ? this.StatusBar + 44 + 'px' : '44px'
  64. //#ifdef MP
  65. let custom = wx.getMenuButtonBoundingClientRect();
  66. let CustomBar = custom.bottom + custom.top - systemInfo.statusBarHeight;
  67. this.barHeight = CustomBar || 0
  68. //#endif
  69. },
  70. /**
  71. * @动态获取用户设备信息
  72. */
  73. baseAppInfo() {
  74. var params = {
  75. networkType: null, //网络类型
  76. deviceBrand: null, //设备品牌
  77. deviceId: null, //设备编号
  78. deviceModel: null, //设备型号
  79. userName: null, //用户账号
  80. longitude: "", //经度
  81. latitude: "", //纬度
  82. };
  83. uni.getNetworkType({
  84. success: function (res) {
  85. params.networkType = res.networkType;
  86. },
  87. });
  88. // 获取系统信息
  89. const systemInfo = uni.getSystemInfoSync();
  90. params.deviceBrand = systemInfo.deviceBrand;
  91. params.deviceId = systemInfo.deviceId;
  92. params.deviceModel = systemInfo.deviceModel;
  93. params.operateSystem = systemInfo.platform;
  94. uni.getLocation({
  95. type: "gcj02",
  96. geocode: true,
  97. highAccuracyExpireTime: 5000,
  98. success: (res) => {
  99. params.longitude = res.longitude.toString();
  100. params.latitude = res.latitude.toString();
  101. baseAppInfoApi(params).then((res) => { })
  102. },
  103. fail: (res) => {
  104. },
  105. });
  106. },
  107. /**
  108. * @消息推送监听
  109. */
  110. pushListener() {
  111. //获取应用的CID
  112. uni.getPushClientId({
  113. success: (res) => {
  114. this.pushClientId = res.cid
  115. },
  116. fail(err) {
  117. console.log(err);
  118. },
  119. });
  120. const platform = uni.getSystemInfoSync().platform;
  121. // 接收推送信息 在线
  122. plus.push.addEventListener("receive", (res) => {
  123. uni.createPushMessage({
  124. title: res.title,
  125. content: res.content,
  126. });
  127. });
  128. // 点击推送信息
  129. plus.push.addEventListener("click", (res) => {
  130. console.log(res);
  131. if (res.aps) {
  132. if ("url" in res.payload) {
  133. } else {
  134. }
  135. console.log(res.payload);
  136. }
  137. });
  138. },
  139. /**
  140. * @点击登录
  141. */
  142. handleToLogin() {
  143. tab.reLaunch("/pages/login");
  144. },
  145. /**
  146. * @点击头像
  147. */
  148. handleToAvatar(type) {
  149. if (type == 1) {
  150. uni.chooseImage({
  151. count: 1, //默认9
  152. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  153. sourceType: ["album", "camera"], //从相册选择、摄像头
  154. success: function (res) {
  155. this.uploadApi(res);
  156. },
  157. });
  158. } else if (type == 2) {
  159. tab.navigateTo("/pages/mine/avatar/index");
  160. }
  161. },
  162. /**
  163. * @upload上传头像
  164. * @api接口请求
  165. */
  166. uploadApi(res) {
  167. const useStore = useStores();
  168. let data = { name: "file", filePath: res.tempFilePaths[0] };
  169. uploadAvatar(data).then((response) => {
  170. useStore.avatar = response.data.url;
  171. updateUserProfile({
  172. avatar: response.data.url,
  173. }).then(() => { });
  174. });
  175. },
  176. /**
  177. * @常见问题
  178. */
  179. handleHelp() {
  180. tab.navigateTo("/pages/mine/help/index");
  181. },
  182. /**
  183. * @我的信息
  184. */
  185. handleToEditInfo() {
  186. tab.navigateTo("/pages/mine/info/index");
  187. },
  188. /**
  189. * @关于我们
  190. */
  191. handleAbout() {
  192. tab.navigateTo("/pages/mine/about/index");
  193. },
  194. /**
  195. * @清理缓存
  196. */
  197. handleCleanTmp() {
  198. // #ifdef H5
  199. uni.showToast({
  200. title: "缓存清理完成",
  201. duration: 2000,
  202. mask: true,
  203. });
  204. // #endif
  205. // #ifdef APP-PLUS
  206. setting.clearCache();//清除应用访问缓存
  207. // #endif
  208. },
  209. /**
  210. * @检查更新
  211. */
  212. handleToUpgrade({ success, error }) {
  213. let data = {
  214. _api_key: "fba7440cd37400b6ff46e303896af4df",
  215. appKey: "cbd3508235d03365f4253f6aae6b68ab",
  216. buildVersion: config.appInfo.version,
  217. };
  218. modal.loading("加载中");
  219. checkUpdates(data).then((res) => {
  220. if (res.code == 0) {
  221. let platform = uni.getSystemInfoSync().platform; //手机平台
  222. if (res.data.buildHaveNewVersion == true) {
  223. //安卓手机弹窗升级
  224. if (platform === "android") {
  225. success(res)
  226. }
  227. //IOS无法在线升级提示到商店下载
  228. else {
  229. uni.showModal({
  230. title: "发现新版本 " + res.data.buildVersion,
  231. content: "请到App store进行升级",
  232. showCancel: false,
  233. });
  234. }
  235. } else {
  236. modal.msg("您的软件版本已是最新");
  237. }
  238. modal.closeLoading();
  239. }
  240. });
  241. },
  242. /**
  243. * @新消息通知
  244. */
  245. handleToMessage() {
  246. tab.navigateTo("/pages/mine/msg/index");
  247. },
  248. /**
  249. * @账号与安全
  250. */
  251. handleToSecure() {
  252. tab.navigateTo("/pages/mine/secure/index");
  253. },
  254. /**
  255. * @设置
  256. */
  257. handleSetting() {
  258. tab.navigateTo("/pages/mine/setting/index");
  259. },
  260. /**
  261. * @退出登录
  262. */
  263. handleLogout() {
  264. const useStore = useStores();
  265. modal.confirm("确定注销并退出系统吗?").then(() => {
  266. useStore.LogOut().then(() => {
  267. tab.reLaunch("/pages/index");
  268. });
  269. });
  270. },
  271. SET_THEMECOLOR(themeColor) {
  272. this.themeColor = themeColor;
  273. storage.set("themeColor", themeColor);
  274. },
  275. SET_FINGERPRINT(array) {
  276. this.fingerprintUserList = array;
  277. storage.set("fingerprintUserList", array);
  278. }
  279. },
  280. });
  281. export default settingStore;