小说小程序前端代码仓库(小程序)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
7.0 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. <template>
  2. <view class="achievement-page">
  3. <navbar title="读者成就设置" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="achievement-card">
  5. <view class="card-title-row">
  6. <view class="card-title">阅读成就设置</view>
  7. <view v-if="statusText" class="status-tag" :class="statusClass">{{ statusText }}</view>
  8. </view>
  9. <view class="achievement-list">
  10. <view class="achievement-item"
  11. v-for="(item, index) in list"
  12. :key="index">
  13. <image class="badge-img"
  14. :src="item.image"
  15. mode="aspectFill" />
  16. <view class="">
  17. <view class="input-area">
  18. <view class="label-row">
  19. <text class="required">*</text>
  20. <text class="label">{{ item.title }}</text>
  21. </view>
  22. <input class="input"
  23. v-model="form[keys[index] + 'Name']"
  24. placeholder="请输入"
  25. placeholder-class="input-placeholder"
  26. :disabled="!canEdit" />
  27. </view>
  28. <view class="input-area" v-if="form[keys[index] + 'Num']">
  29. <view class="label-row">
  30. <text class="label">达成人数</text>
  31. </view>
  32. <view class="Num">
  33. {{ form[keys[index] + 'Num'] || 0 }}
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- <view class="divider"></view>
  39. <view class="achievement-item">
  40. <image class="badge-img"
  41. src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wUsFZgl70iE4tI7b_HKaKgHaHa?w=166&h=180&c=7&r=0&o=5&dpr=1.1&pid=1.7"
  42. mode="aspectFill" />
  43. <view class="input-area">
  44. <view class="label-row">
  45. <text class="required">*</text>
  46. <text class="label">二级成就名称</text>
  47. </view>
  48. <input class="input" v-model="level2" placeholder="请输入" placeholder-class="input-placeholder" />
  49. </view>
  50. </view>
  51. <view class="divider"></view>
  52. <view class="achievement-item">
  53. <image class="badge-img"
  54. src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wUsFZgl70iE4tI7b_HKaKgHaHa?w=166&h=180&c=7&r=0&o=5&dpr=1.1&pid=1.7"
  55. mode="aspectFill" />
  56. <view class="input-area">
  57. <view class="label-row">
  58. <text class="required">*</text>
  59. <text class="label">三级成就名称</text>
  60. </view>
  61. <input class="input" v-model="level3" placeholder="请输入" placeholder-class="input-placeholder" />
  62. </view>
  63. </view> -->
  64. </view>
  65. </view>
  66. <view class="bottom-btn-area">
  67. <button class="submit-btn" :disabled="!canEdit"
  68. :class="{disabled: !canEdit}"
  69. @click="submit">
  70. {{ submitButtonText }}
  71. </button>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import mixinsList from '@/mixins/list.js'
  77. export default {
  78. mixins: [mixinsList],
  79. data() {
  80. return {
  81. mixinsListApi : 'getAchievementList',
  82. keys : ['one', 'two', 'three'],
  83. form : {},
  84. }
  85. },
  86. computed: {
  87. // 判断是否可以编辑
  88. canEdit() {
  89. // status=0(审核中)不能编辑,status=1(已通过)、status=2(不通过)和第一次提交(没有form.id)可以编辑
  90. return this.form.status != 0
  91. },
  92. // 状态文本
  93. statusText() {
  94. // 第一次提交时不显示状态标签
  95. if (!this.form.id) return ''
  96. // 根据状态返回文本
  97. if (this.form.status == 0) return '审核中'
  98. if (this.form.status == 1) return '已通过'
  99. if (this.form.status == 2) return '不通过'
  100. return ''
  101. },
  102. // 状态样式类
  103. statusClass() {
  104. if (this.form.status == 0) return 'status-pending'
  105. if (this.form.status == 1) return 'status-approved'
  106. if (this.form.status == 2) return 'status-rejected'
  107. return ''
  108. },
  109. // 提交按钮文本
  110. submitButtonText() {
  111. if (!this.form.id) return '提交申请'
  112. if (this.form.status == 2) return '重新提交'
  113. return '设置'
  114. }
  115. },
  116. onLoad() {
  117. this.getDetail()
  118. },
  119. methods: {
  120. async getDetail(){
  121. const data = await this.$fetch('getAchievement') || {}
  122. // 使用展开运算符确保响应式更新
  123. this.form = { ...data }
  124. },
  125. async submit() {
  126. if(this.$utils.verificationAll(this.form, {
  127. oneName : '请填写' + this.list[0].title,
  128. twoName : '请填写' + this.list[1].title,
  129. threeName : '请填写' + this.list[2].title,
  130. })){
  131. return
  132. }
  133. let data = {
  134. oneName : this.form.oneName,
  135. twoName : this.form.twoName,
  136. threeName : this.form.threeName,
  137. status : 0
  138. }
  139. if(this.form.id){
  140. data.id = this.form.id
  141. }
  142. await this.$fetch('setAchievementName', data)
  143. uni.showToast({
  144. title: '提交成功',
  145. icon: 'none'
  146. })
  147. setTimeout(() => {
  148. uni.navigateBack()
  149. }, 1000)
  150. },
  151. }
  152. }
  153. </script>
  154. <style scoped lang="scss">
  155. .achievement-page {
  156. min-height: 100vh;
  157. background: #f7f8fa;
  158. display: flex;
  159. flex-direction: column;
  160. }
  161. .achievement-card {
  162. background: #fff;
  163. border-radius: 20rpx;
  164. margin: 40rpx 32rpx 0 32rpx;
  165. padding: 32rpx 24rpx;
  166. box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.04);
  167. }
  168. .card-title-row {
  169. display: flex;
  170. align-items: center;
  171. justify-content: space-between;
  172. }
  173. .card-title {
  174. font-size: 32rpx;
  175. font-weight: bold;
  176. margin-bottom: 32rpx;
  177. }
  178. .status-tag {
  179. font-size: 24rpx;
  180. border-radius: 10rpx;
  181. padding: 6rpx 24rpx;
  182. margin-left: 20rpx;
  183. margin-bottom: 32rpx;
  184. }
  185. .status-pending {
  186. background: #ff9500;
  187. color: #fff;
  188. }
  189. .status-approved {
  190. background: #07c160;
  191. color: #fff;
  192. }
  193. .status-rejected {
  194. background: #e23d3d;
  195. color: #fff;
  196. }
  197. .achievement-list {
  198. display: flex;
  199. flex-direction: column;
  200. gap: 0;
  201. }
  202. .achievement-item {
  203. display: flex;
  204. align-items: flex-start;
  205. padding: 18rpx 0 10rpx 0;
  206. }
  207. .badge-img {
  208. width: 72rpx;
  209. height: 72rpx;
  210. margin-right: 20rpx;
  211. border-radius: 50%;
  212. background: #f5f5f5;
  213. object-fit: cover;
  214. border: 2rpx solid #fff;
  215. box-shadow: 0 2rpx 8rpx 0 rgba(0, 0, 0, 0.04);
  216. }
  217. .input-area {
  218. margin-top: 15rpx;
  219. flex: 1;
  220. display: flex;
  221. flex-direction: column;
  222. justify-content: flex-start;
  223. }
  224. .label-row {
  225. display: flex;
  226. align-items: center;
  227. margin-bottom: 6rpx;
  228. }
  229. .required {
  230. color: #e23d3d;
  231. font-size: 28rpx;
  232. margin-right: 4rpx;
  233. }
  234. .label {
  235. font-size: 24rpx;
  236. color: #999;
  237. font-weight: bold;
  238. }
  239. .Num{
  240. }
  241. .input {
  242. width: 100%;
  243. border: none;
  244. border-bottom: 1.5rpx solid #ececec;
  245. font-size: 28rpx;
  246. background: transparent;
  247. padding: 16rpx 0;
  248. margin-bottom: 2rpx;
  249. }
  250. .input:disabled {
  251. background: #f5f5f5;
  252. color: #999;
  253. }
  254. .input-placeholder {
  255. color: #d2d2d2;
  256. font-size: 26rpx;
  257. }
  258. .divider {
  259. height: 1rpx;
  260. background: #f3f3f3;
  261. margin: 0 0 0 92rpx;
  262. }
  263. .bottom-btn-area {
  264. margin-top: auto;
  265. padding: 48rpx 32rpx 32rpx 32rpx;
  266. background: transparent;
  267. }
  268. .submit-btn {
  269. width: 100%;
  270. height: 88rpx;
  271. background: #0a2e6d;
  272. color: #fff;
  273. font-size: 32rpx;
  274. border-radius: 44rpx;
  275. font-weight: bold;
  276. letter-spacing: 2rpx;
  277. transition: background 0.2s;
  278. }
  279. .submit-btn.disabled {
  280. background: #aaa;
  281. color: #fff;
  282. }
  283. .submit-btn.pending {
  284. background: #0a226d;
  285. color: #fff;
  286. }
  287. </style>