index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div class="protocol-config-setting">
  3. <!-- 顶部提示信息 -->
  4. <div class="setting-hint">
  5. <el-alert :closable="false" type="info" class="custom-alert">
  6. <template #title>
  7. <div class="alert-content">
  8. <el-icon class="info-icon">
  9. <InfoFilled />
  10. </el-icon>
  11. <span>协议配置:目前支持用户协议、隐私政策、履约者说明、托运协议、宠物洗护服务规范;请确保内容准确合规。</span>
  12. </div>
  13. </template>
  14. </el-alert>
  15. </div>
  16. <!-- 配置表单区 -->
  17. <div class="setting-body">
  18. <el-form ref="protocolFormRef" :model="form" :rules="rules" label-width="140px" label-position="right"
  19. class="premium-setting-form">
  20. <!-- 协议选择 -->
  21. <el-form-item label="协议选择:">
  22. <el-radio-group v-model="currentId" @change="handleTypeChange" class="custom-radio-group">
  23. <el-radio :label="1" border>用户协议</el-radio>
  24. <el-radio :label="2" border>隐私政策</el-radio>
  25. <el-radio :label="3" border>履约者说明</el-radio>
  26. <el-radio :label="4" border>托运协议</el-radio>
  27. <el-radio :label="5" border>宠物洗护服务规范</el-radio>
  28. </el-radio-group>
  29. </el-form-item>
  30. <!-- 协议标题 -->
  31. <el-form-item label="协议标题:" prop="title">
  32. <el-input v-model="form.title" placeholder="请输入协议标题" class="config-input" />
  33. </el-form-item>
  34. <!-- 协议内容 -->
  35. <el-form-item label="协议内容:" prop="content">
  36. <Editor v-model="form.content" :min-height="400" class="config-editor" />
  37. <div class="form-tip">协议内容将以 HTML 格式保存,支持图片和视频插入。</div>
  38. </el-form-item>
  39. <!-- 保存按钮 -->
  40. <el-form-item class="action-item">
  41. <el-button type="primary" class="save-btn" :loading="buttonLoading" @click="submitForm">保存设置</el-button>
  42. </el-form-item>
  43. </el-form>
  44. </div>
  45. </div>
  46. </template>
  47. <script setup name="ProtocolConfig" lang="ts">
  48. import { ref, reactive, onMounted, getCurrentInstance, ComponentInternalInstance } from 'vue';
  49. import { getAgreement, editAgreement } from '@/api/system/agreement';
  50. import { InfoFilled } from '@element-plus/icons-vue';
  51. import { ElForm } from 'element-plus';
  52. import Editor from '@/components/Editor/index.vue';
  53. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  54. const buttonLoading = ref(false);
  55. const protocolFormRef = ref<InstanceType<typeof ElForm>>();
  56. const currentId = ref(1); // 默认选择用户协议 ID:1
  57. const form = reactive({
  58. id: undefined,
  59. title: '',
  60. content: ''
  61. });
  62. const rules = {
  63. title: [{ required: true, message: "协议标题不能为空", trigger: "blur" }],
  64. content: [{ required: true, message: "协议内容不能为空", trigger: "blur" }],
  65. };
  66. /** 加载协议配置 */
  67. const loadProtocolConfig = async (id: number) => {
  68. try {
  69. const res = await getAgreement(id);
  70. if (res.data) {
  71. Object.assign(form, res.data);
  72. }
  73. } catch (error) {
  74. console.error('获取协议信息失败', error);
  75. }
  76. };
  77. /** 切换协议 */
  78. const handleTypeChange = (val: any) => {
  79. loadProtocolConfig(val as number);
  80. };
  81. /** 提交按钮 */
  82. const submitForm = () => {
  83. protocolFormRef.value?.validate(async (valid: boolean) => {
  84. if (valid) {
  85. buttonLoading.value = true;
  86. try {
  87. // 将 content 按照 Base64 方式编码,同时处理非西欧语言字符集
  88. const contentBase64 = btoa(unescape(encodeURIComponent(form.content)));
  89. const submitData = {
  90. id: form.id || currentId.value,
  91. title: form.title,
  92. content: contentBase64
  93. };
  94. await editAgreement(submitData);
  95. proxy?.$modal.msgSuccess("保存成功");
  96. await loadProtocolConfig(currentId.value);
  97. } catch (error) {
  98. console.error('保存协议信息失败', error);
  99. } finally {
  100. buttonLoading.value = false;
  101. }
  102. }
  103. });
  104. };
  105. onMounted(() => {
  106. loadProtocolConfig(currentId.value);
  107. });
  108. </script>
  109. <style scoped lang="scss">
  110. .protocol-config-setting {
  111. padding: 8px 0;
  112. }
  113. .setting-hint {
  114. margin-bottom: 32px;
  115. .custom-alert {
  116. background-color: #e8f4ff;
  117. border: none;
  118. border-radius: 8px;
  119. padding: 12px 16px;
  120. .alert-content {
  121. display: flex;
  122. align-items: center;
  123. gap: 10px;
  124. color: #1890ff;
  125. font-size: 14px;
  126. line-height: 1.5;
  127. .info-icon {
  128. font-size: 18px;
  129. }
  130. }
  131. }
  132. }
  133. .setting-body {
  134. padding-left: 20px;
  135. }
  136. .premium-setting-form {
  137. :deep(.el-form-item__label) {
  138. font-weight: 500;
  139. color: #4e5969;
  140. padding-right: 24px;
  141. }
  142. .config-input {
  143. max-width: 520px;
  144. :deep(.el-input__wrapper) {
  145. box-shadow: 0 0 0 1px #e5e6eb inset;
  146. padding: 4px 12px;
  147. border-radius: 6px;
  148. &.is-focus {
  149. box-shadow: 0 0 0 1px #409eff inset;
  150. }
  151. }
  152. }
  153. .config-editor {
  154. width: 100%;
  155. max-width: 1000px;
  156. }
  157. .form-tip {
  158. font-size: 13px;
  159. color: #86909c;
  160. margin-top: 8px;
  161. line-height: 1.4;
  162. }
  163. .custom-radio-group {
  164. :deep(.el-radio) {
  165. margin-right: 16px;
  166. border-radius: 6px;
  167. padding: 0 20px;
  168. height: 36px;
  169. &.is-bordered.is-checked {
  170. border-color: #409eff;
  171. background-color: rgba(64, 158, 255, 0.04);
  172. }
  173. .el-radio__label {
  174. font-size: 14px;
  175. }
  176. }
  177. }
  178. .action-item {
  179. margin-top: 40px;
  180. }
  181. .save-btn {
  182. padding: 12px 32px;
  183. height: auto;
  184. font-size: 15px;
  185. font-weight: 500;
  186. border-radius: 6px;
  187. box-shadow: 0 4px 10px rgba(64, 158, 255, 0.2);
  188. }
  189. }
  190. </style>