123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <template>
- <view class="setting">
- <view class="header-bg"></view>
- <view class="block b1">
- <view class="row portrait">
- <image class="image" src="../../static/images/login/logo.png" mode="scaleToFill"></image>
- </view>
- <view class="row">
- <view class="label">
- 昵称 <text class="info">{{nickname}}</text>
- </view>
- <view class="option">
- <navigator url="/pages/user/nickname" hover-class="none">修改</navigator>
- </view>
- </view>
- </view>
- <view class="block b2">
- <view class="row">
- <view class="label">支付宝绑定</view>
- <view class="option">
- <navigator url="/pages/user/bind-alipay" hover-class="none">
- 未绑定
- </navigator>
- </view>
- </view>
- <view class="line"></view>
- <view class="row">
- <view>微信绑定</view>
- <view class="option">未绑定</view>
- </view>
- </view>
- <view class="block b3">
- <view class="row">
- <view class="label">修改手机号 <text class="info">{{mobile}}</text></view>
- <view class="option">已绑定</view>
- </view>
- <view class="line"></view>
- <view class="row">
- <navigator url="/pages/user/reset-pass" hover-class="none">
- <view class="label">修改密码</view>
- <view class="option"></view>
- </navigator>
- </view>
- </view>
- <view class="block b4">
- <view class="row">
- <view class="label">支付密码</view>
- <view class="option">
- <navigator url="/pages/user/safe-pass" hover-class="none">
- {{$store.state.user.is_set_safe_pass?'已设置':'未设置'}}
- </navigator>
- </view>
- </view>
- </view>
- <view class="block b5">
- <view class="row">
- <view class="label">清除缓存 <text class="info">{{fileSizeString}}</text></view>
- <view class="option"><button class="clear-cache-btn" type="default" @tap="clearCache()">清除缓存</button>
- </view>
- </view>
- </view>
- <view class="logout-block">
- <button class="logout-btn" type="default" @tap="logout()">退出登录</button>
- </view>
- </view>
- </template>
- <script>
- import {
- mapState
- } from 'vuex'
- export default {
- data() {
- return {
- fileSizeString: "计算中..."
- }
- },
- computed: mapState({
- nickname: state => state.user.nickname,
- mobile: state => state.user.mobile
- }),
- onLoad() {
- const info = uni.getStorageInfoSync();
- console.log(info)
- this.formatSize();
- },
- methods: {
- logout() {
- this.$store.dispatch("user/logout")
- uni.$emit("logout")
- uni.navigateBack({
- delta: 999,
- animationType: 'none',
- })
- uni.switchTab({
- url: "/pages/home/home",
- success() {
- uni.navigateTo({
- url: '/pages/user/login'
- })
- }
- })
- },
- formatSize() {
- let that = this;
- plus.cache.calculate(function(size) {
- let sizeCache = parseInt(size);
- if (sizeCache == 0) {
- that.fileSizeString = "0B";
- } else if (sizeCache < 1024) {
- that.fileSizeString = sizeCache + "B";
- } else if (sizeCache < 1048576) {
- that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
- } else if (sizeCache < 1073741824) {
- that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
- } else {
- that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
- }
- });
- },
- clearCache() {
- let that = this;
- let os = plus.os.name;
- if (os == 'Android') {
- let main = plus.android.runtimeMainActivity();
- let sdRoot = main.getCacheDir();
- let files = plus.android.invoke(sdRoot, "listFiles");
- let len = files.length;
- for (let i = 0; i < len; i++) {
- let filePath = '' + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
- plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
- if (entry.isDirectory) {
- entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录
- uni.showToast({
- icon: 'none',
- title: '缓存清理完成',
- duration: 2000
- });
- that.formatSize(); // 重新计算缓存
- }, function(e) {
- console.log(e.message)
- });
- } else {
- entry.remove();
- }
- }, function(e) {
- console.log('文件路径读取失败')
- });
- }
- } else { // ios暂时未找到清理缓存的方法,以下是官方提供的方法,但是无效,会报错
- plus.cache.clear(function() {
- uni.showToast({
- icon: 'none',
- title: '缓存清理完成',
- duration: 2000
- });
- that.formatSize();
- });
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .setting {
- overflow: hidden;
- position: relative;
- }
- .header-bg {
- background-color: $primary-color;
- height: 120upx;
- position: absolute;
- top: 0;
- width: 100%;
- z-index: 1;
- }
- .portrait {
- justify-content: center !important;
- margin-top: 20upx;
- .image {
- width: 168upx;
- height: 168upx;
- border: 10upx solid $primary-color;
- border-radius: 100upx;
- }
- }
- .block {
- border-radius: 20upx;
- background-color: white;
- margin: 20upx;
- position: relative;
- overflow: hidden;
- z-index: 2;
- .row {
- display: flex;
- justify-content: space-between;
- padding: 20upx 40upx;
- align-items: center;
- font-size: 28upx;
- .info {
- color: #999999;
- font-size: 26upx;
- display: inline-block;
- margin-left: 20upx;
- }
- .option {
- color: #999999;
- }
- }
- }
- .logout-block {
- margin: 20upx;
- }
- .clear-cache-btn {
- line-height: normal;
- padding: 4upx 20upx;
- background: white;
- border: 2upx solid $primary-color;
- font-size: 24upx;
- border-radius: 50upx;
- color: $primary-color;
- }
- .logout-btn {
- background: $primary-color;
- color: white;
- font-size: 30upx;
- line-height: 80upx;
- }
- .line {
- border: 2upx solid #EEEEEE;
- transform: scale(0.9, 0.5);
- }
- </style>
|