setting.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="app-page" :class="{ 'is-balck grey-darken-6': isBlackTheme }">
  3. <tm-form v-if="!loading" ref="formData">
  4. <!-- <tm-sheet :shadow="24" :padding="[12, 24]" :margin="[24, 24]">
  5. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  6. <text class="text-size-n text-weight-b ">标题</text>
  7. <text class="text-grey text-size-xs px-10">副标题/描述</text>
  8. </view>
  9. <view class="sheet-content">内容区域</view>
  10. </tm-sheet> -->
  11. <tm-sheet :shadow="6" :padding="[12, 24]" :margin="[24, 24]">
  12. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  13. <text class="text-size-n text-weight-b ">布局</text>
  14. <text class="text-grey text-size-xs px-10 ml-12">应用以及文章列表布局设置</text>
  15. </view>
  16. <view class="sheet-content">
  17. <tm-pickers
  18. title="请选择首页布局"
  19. btn-color="light-blue"
  20. :default-value.sync="homeLayout.selectDefault"
  21. rang-key="name"
  22. :list="homeLayout.list"
  23. @confirm="fnOnHomeLayoutConfirm"
  24. >
  25. <tm-input
  26. name="status"
  27. required
  28. title="首页布局"
  29. placeholder="请选择首页布局"
  30. disabled
  31. :value="homeLayout.selectLabel"
  32. right-icon="icon-angle-right"
  33. ></tm-input>
  34. </tm-pickers>
  35. <tm-pickers
  36. title="请选择文章卡片样式"
  37. btn-color="light-blue"
  38. :default-value.sync="articleCardStyle.selectDefault"
  39. rang-key="name"
  40. :list="articleCardStyle.list"
  41. @confirm="fnOnArticleCardStyleConfirm"
  42. >
  43. <tm-input
  44. name="status"
  45. required
  46. title="卡片样式"
  47. placeholder="请选择文章卡片样式"
  48. disabled
  49. :value="articleCardStyle.selectLabel"
  50. right-icon="icon-angle-right"
  51. ></tm-input>
  52. </tm-pickers>
  53. </view>
  54. </tm-sheet>
  55. <tm-sheet v-if="false" :shadow="24" :padding="[12, 24]" :margin="[24, 24]">
  56. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  57. <text class="text-size-n text-weight-b ">外观</text>
  58. <text class="text-grey text-size-xs px-10">设置应用主题色/暗黑模式等</text>
  59. </view>
  60. <view class="sheet-content">
  61. <!-- 内容区域 -->
  62. <text class="ma-24">todo</text>
  63. </view>
  64. </tm-sheet>
  65. <tm-sheet :shadow="6" :padding="[12, 24]" :margin="[24, 24]">
  66. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  67. <text class="text-size-n text-weight-b ">功能</text>
  68. <text class="text-grey text-size-xs px-10 ml-12">一些常用的功能性设置</text>
  69. </view>
  70. <view class="sheet-content">
  71. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  72. <text class="text-size-m">显示完整统计</text>
  73. <tm-switch v-model="appSettings.about.showAllCount" color="light-blue" :text="['是', '否']"></tm-switch>
  74. </view>
  75. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  76. <text class="text-size-m ">链接直接打开</text>
  77. <tm-switch v-model="appSettings.contact.isLinkCopy" color="light-blue" :text="['是', '否']"></tm-switch>
  78. </view>
  79. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  80. <text class="text-size-m ">图库瀑布流模式</text>
  81. <tm-switch v-model="appSettings.gallery.useWaterfull" color="light-blue" :text="['是', '否']"></tm-switch>
  82. </view>
  83. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  84. <text class="text-size-m ">友链简洁模式</text>
  85. <tm-switch v-model="appSettings.links.useSimple" color="light-blue" :text="['是', '否']"></tm-switch>
  86. </view>
  87. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  88. <text class="text-size-m ">轮播图指示器</text>
  89. <tm-switch v-model="appSettings.banner.useDot" color="light-blue" :text="['是', '否']"></tm-switch>
  90. </view>
  91. <view v-if="appSettings.banner.useDot" class="mx-32 my-24 border-b-1 pb-24 flex-between">
  92. <text class="text-size-m ">轮播图指示器位置</text>
  93. <tm-groupradio name="dotPosition" @change="fnOnBannerDotChange">
  94. <tm-radio
  95. :name="item.name"
  96. :size="28"
  97. color="light-blue"
  98. v-for="(item, index) in dotPositionList"
  99. :key="index"
  100. v-model="item.checked"
  101. :label="item.name"
  102. ></tm-radio>
  103. </tm-groupradio>
  104. </view>
  105. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  106. <text class="text-size-m ">显示后台入口</text>
  107. <tm-switch v-model="appSettings.about.showAdmin" color="light-blue" :text="['是', '否']"></tm-switch>
  108. </view>
  109. </view>
  110. </tm-sheet>
  111. </tm-form>
  112. <!-- 操作区域 -->
  113. <view v-if="!loading" class="btn-bar flex flex-center bg-white">
  114. <tm-button theme="light-blue" :shadow="0" block :height="70" @click="fnOnSave()">保存设置</tm-button>
  115. <tm-button theme="red" :shadow="0" block :height="70" @click="fnOnSaveDefault()">恢复默认设置</tm-button>
  116. <tm-button theme="blue-grey" :shadow="0" block :height="70" @click="fnOnBack()">返回</tm-button>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. import { _DefaultAppSettings } from '@/utils/app.js';
  122. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  123. import tmForm from '@/tm-vuetify/components/tm-form/tm-form.vue';
  124. import tmPickers from '@/tm-vuetify/components/tm-pickers/tm-pickers.vue';
  125. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  126. import tmSwitch from '@/tm-vuetify/components/tm-switch/tm-switch.vue';
  127. import tmSheet from '@/tm-vuetify/components/tm-sheet/tm-sheet.vue';
  128. import tmGroupradio from '@/tm-vuetify/components/tm-groupradio/tm-groupradio.vue';
  129. import tmRadio from '@/tm-vuetify/components/tm-radio/tm-radio.vue';
  130. export default {
  131. components: {
  132. tmButton,
  133. tmForm,
  134. tmPickers,
  135. tmInput,
  136. tmSwitch,
  137. tmSheet,
  138. tmGroupradio,
  139. tmRadio
  140. },
  141. data() {
  142. return {
  143. isBlackTheme: false,
  144. loading: true,
  145. appSettings: {},
  146. isSaved: true,
  147. firstLoad: true,
  148. homeLayout: {
  149. list: [{ name: '一行一列', value: 'h_row_col1' }, { name: '一行两列', value: 'h_row_col2' }],
  150. selectDefault: ['一行一列'],
  151. selectLabel: '一行一列',
  152. selectValue: 'h_row_col1'
  153. },
  154. articleCardStyle: {
  155. list: [
  156. { name: '左图右文', value: 'lr_image_text' },
  157. { name: '左文右图', value: 'lr_text_image' },
  158. { name: '上图下文', value: 'tb_image_text' },
  159. { name: '上文下图', value: 'tb_text_image' },
  160. { name: '只有文字', value: 'only_text' }
  161. ],
  162. selectDefault: ['左图右文'],
  163. selectLabel: '左图右文',
  164. selectValue: 'lr_image_text'
  165. },
  166. dotPositionList: [{ name: '右边', value: 'right', checked: true }, { name: '下边', value: 'bottom', checked: false }]
  167. };
  168. },
  169. watch: {
  170. appSettings: {
  171. deep: true,
  172. handler() {
  173. if (this.firstLoad) {
  174. this.firstLoad = false;
  175. } else {
  176. this.isSaved = false;
  177. }
  178. }
  179. }
  180. },
  181. onLoad(e) {
  182. this.fnSetPageTitle('应用设置');
  183. },
  184. created() {
  185. this.appSettings = uni.$tm.vx.getters().setting.getSettings;
  186. this.fnHandleFormatSelect();
  187. uni.showLoading({
  188. title: '加载中...',
  189. mask: true
  190. });
  191. setTimeout(() => {
  192. this.loading = false;
  193. uni.hideLoading();
  194. }, 500);
  195. },
  196. methods: {
  197. // 统一处理选择框的内容
  198. fnHandleFormatSelect() {
  199. // 首页布局
  200. const _homeLayout = this.fnFindObjInList(this.homeLayout.list, 'value', this.appSettings.layout.home);
  201. this.homeLayout.selectDefault = [_homeLayout.name];
  202. this.homeLayout.selectLabel = _homeLayout.name;
  203. this.homeLayout.selectValue = _homeLayout.value;
  204. const _articleCardStyle = this.fnFindObjInList(this.articleCardStyle.list, 'value', this.appSettings.layout.cardType);
  205. this.articleCardStyle.selectDefault = [_articleCardStyle.name];
  206. this.articleCardStyle.selectLabel = _articleCardStyle.name;
  207. this.articleCardStyle.selectValue = _articleCardStyle.value;
  208. },
  209. // 在集合中找匹配的对象
  210. fnFindObjInList(list, key, value) {
  211. return list.find(x => x[key] == value);
  212. },
  213. fnOnBannerDotChange(e) {
  214. const _select = e[0];
  215. if (_select.index == 0 && _select.checked) {
  216. this.appSettings.banner.dotPosition = 'right';
  217. }
  218. if (_select.index == 1 && _select.checked) {
  219. this.appSettings.banner.dotPosition = 'bottom';
  220. }
  221. },
  222. // 首页布局
  223. fnOnHomeLayoutConfirm(e) {
  224. const _select = e[0].data;
  225. this.homeLayout.selectDefault = [_select.name];
  226. this.homeLayout.selectLabel = _select.name;
  227. this.homeLayout.selectValue = _select.value;
  228. this.appSettings.layout.home = _select.value;
  229. },
  230. // 文章卡片样式
  231. fnOnArticleCardStyleConfirm(e) {
  232. const _select = e[0].data;
  233. this.articleCardStyle.selectDefault = [_select.name];
  234. this.articleCardStyle.selectLabel = _select.name;
  235. this.articleCardStyle.selectValue = _select.value;
  236. this.appSettings.layout.cardType = _select.value;
  237. },
  238. // 保存
  239. fnOnSave() {
  240. this.isSaved = true;
  241. this.$tm.vx.commit('setting/setSettings', this.appSettings);
  242. uni.$tm.toast('保存成功,部分设置在重启后生效!');
  243. },
  244. // 使用默认配置
  245. fnOnSaveDefault() {
  246. uni.$eShowModal({
  247. title: '提示',
  248. content: '您确定要恢复为默认的设置吗?',
  249. showCancel: true,
  250. cancelText: '否',
  251. cancelColor: '#999999',
  252. confirmText: '是',
  253. confirmColor: '#03a9f4'
  254. })
  255. .then(res => {
  256. this.isSaved = true;
  257. uni.$tm.vx.actions('setting/updateDefaultAppSettings');
  258. uni.$tm.toast('系统设置已恢复为默认配置,部分设置在重启后生效!');
  259. })
  260. .catch(err => {});
  261. },
  262. fnOnBack() {
  263. if (this.isSaved) {
  264. uni.navigateBack();
  265. }
  266. uni.$eShowModal({
  267. title: '提示',
  268. content: '您当前可能有未保存的数据,确定返回吗?',
  269. showCancel: true,
  270. cancelText: '否',
  271. cancelColor: '#999999',
  272. confirmText: '是',
  273. confirmColor: '#03a9f4'
  274. })
  275. .then(res => {
  276. uni.navigateBack();
  277. this.isSaved = true;
  278. })
  279. .catch(err => {});
  280. }
  281. }
  282. };
  283. </script>
  284. <style scoped lang="scss">
  285. .app-page {
  286. box-sizing: border-box;
  287. padding-bottom: 120rpx;
  288. .btn-bar {
  289. width: 100vw;
  290. position: fixed;
  291. left: 0;
  292. bottom: 0;
  293. box-sizing: border-box;
  294. padding: 24rpx;
  295. gap: 0 24rpx;
  296. box-shadow: 0rpx -6rpx 24rpx rgba(0, 0, 0, 0.03);
  297. }
  298. }
  299. .required {
  300. position: relative;
  301. padding-left: 18rpx;
  302. &:before {
  303. content: '*';
  304. position: absolute;
  305. left: -4rpx;
  306. top: 50%;
  307. transform: translateY(-50%);
  308. font-size: 34rpx;
  309. color: rgba(244, 67, 54, 1);
  310. }
  311. }
  312. </style>