• 开发者配置项、开发者选项自定义


    devOptions.vue源码

    1. <template>
    2. <div :class="$options.name" v-if="visible">
    3. <el-dialog
    4. :custom-class="`sg-el-dialog`"
    5. :append-to-body="true"
    6. :close-on-click-modal="false"
    7. :close-on-press-escape="true"
    8. :destroy-on-close="true"
    9. :fullscreen="false"
    10. :show-close="true"
    11. :title="`开发者配置项`"
    12. :width="`520px`"
    13. :visible.sync="visible"
    14. style="animation: none"
    15. >
    16. <template v-if="showDevOptions">
    17. <div style="margin: -20px 0">
    18. <el-select
    19. style="width: 100%"
    20. v-model="selectGroupValue_sgAPI"
    21. @change="changeGroupSelect_sgAPI"
    22. :placeholder="`请选择`"
    23. >
    24. <el-option-group
    25. v-for="group in selectGroupOptions_sgAPI"
    26. :key="group.label"
    27. :label="group.label"
    28. >
    29. <el-option
    30. v-for="item in group.options"
    31. :key="item.value"
    32. :label="`${item.label}${
    33. item.value === `custom` ? `` : `[${item.value}]`
    34. }`"
    35. :value="item.value"
    36. :disabled="item.disabled"
    37. />
    38. el-option-group>
    39. el-select>
    40. <el-input
    41. v-if="showCustomSgAPI"
    42. style="width: 100%; margin-top: 10px"
    43. ref="input"
    44. v-model.trim="inputValue_sgAPI"
    45. maxlength="20"
    46. :show-word-limit="false"
    47. :placeholder="`请输入接口路径(带http或https协议)`"
    48. @focus="$refs.input.select()"
    49. clearable
    50. />
    51. <el-divider />
    52. <el-button type="danger" @click="oneClickRestore" style="width: 100%"
    53. >一键还原所有数据
    54. >
    55. <el-alert
    56. style="margin-top: 10px"
    57. :closable="true"
    58. :close-text="``"
    59. :description="``"
    60. :effect="'light'"
    61. :show-icon="true"
    62. :title="`警告!该操作将丢失所有上传资源数据和配置信息!请谨慎操作!`"
    63. :type="'error'"
    64. >
    65. el-alert>
    66. <el-dialog
    67. :custom-class="'sg-el-dialog'"
    68. :append-to-body="true"
    69. :close-on-click-modal="true"
    70. :close-on-press-escape="true"
    71. :destroy-on-close="true"
    72. :fullscreen="false"
    73. :show-close="true"
    74. :title="`输入登录密码执行一键还原`"
    75. :width="'300px'"
    76. :visible.sync="dialogVisible_oneClickRestore"
    77. >
    78. <div>
    79. <el-input
    80. style="width: 100%"
    81. ref="psw"
    82. type="password"
    83. v-model="psw"
    84. show-password
    85. maxlength="20"
    86. :show-word-limit="false"
    87. :placeholder="`请输入6位以上的密码`"
    88. @focus="$refs.psw.select()"
    89. clearable
    90. />
    91. div>
    92. <div slot="footer">
    93. <el-button type="info" @click="dialogVisible_oneClickRestore = false" plain
    94. >取消
    95. >
    96. <el-button type="primary" @click="confirmRestore">确定el-button>
    97. div>
    98. el-dialog>
    99. div>
    100. <div slot="footer" style="display: flex">
    101. <el-button type="info" @click="visible = false" plain style="flex-grow: 1"
    102. >取消
    103. >
    104. <el-button type="danger" @click="reset">重置配置项el-button>
    105. <el-button type="primary" @click="save">确定并刷新页面el-button>
    106. <el-button type="success" @click="change2Local">模拟本地环境el-button>
    107. div>
    108. template>
    109. <template v-else>
    110. <div style="margin: -20px 0 -10px; display: flex; flex-wrap: nowrap">
    111. <el-input
    112. style="width: 100%; margin-right: 10px"
    113. ref="psw"
    114. type="password"
    115. v-model="psw"
    116. show-password
    117. maxlength="20"
    118. :show-word-limit="false"
    119. :placeholder="`请输入开发者密码`"
    120. @focus="$refs.psw.select()"
    121. clearable
    122. @keyup.enter.native="enterSet"
    123. />
    124. <el-button type="primary" @click="enterSet">进入设置el-button>
    125. div>
    126. template>
    127. el-dialog>
    128. div>
    129. template>
    130. <script>
    131. export default {
    132. name: "api",
    133. components: {},
    134. data() {
    135. return {
    136. visible: false,
    137. showDevOptions: false,
    138. showCustomSgAPI: false,
    139. inputValue_sgAPI: ``,
    140. psw: ``, //开发者密码
    141. dialogVisible_oneClickRestore: false,
    142. selectGroupOptions_sgAPI: this.$global.devConfig.sgAPI,
    143. selectGroupValue_sgAPI: "",
    144. };
    145. },
    146. props: [
    147. "value", //是否显示
    148. "disabled", //是否禁用
    149. "data",
    150. ],
    151. computed: {},
    152. watch: {
    153. value: {
    154. handler(d) {
    155. this.visible = d;
    156. if (d) {
    157. this.psw = ``;
    158. this.showDevOptions = false;
    159. this.init();
    160. }
    161. },
    162. deep: true,
    163. immediate: true,
    164. },
    165. visible(d) {
    166. this.$emit("input", d);
    167. }, //是否显示(双向绑定)
    168. selectGroupValue_sgAPI(d) {
    169. this.showCustomSgAPI = d === `custom`;
    170. },
    171. },
    172. created() {},
    173. mounted() {},
    174. destroyed() {},
    175. methods: {
    176. change2Local(d) {
    177. let query = this.$route.query;
    178. query.isLocal = true;
    179. let href = `${this.$g.getWebURLBeforeHash()}/${
    180. this.$router.resolve({
    181. path: this.$route.path,
    182. query,
    183. }).href
    184. }`;
    185. window.open(href, "_target");
    186. this.$g.screen.closeWebPage();
    187. },
    188. enterSet(d) {
    189. if (!this.psw)
    190. return this.$message.error(this.$refs.psw.$el.querySelector("input").placeholder);
    191. if (this.psw == this.$global.devConfig.devPassword) {
    192. this.showDevOptions = true;
    193. } else {
    194. this.showDevOptions = false;
    195. this.$message.error(`密码不正确`);
    196. }
    197. },
    198. //初始化
    199. init({ d } = {}) {
    200. let sgAPI = localStorage.sgAPI || this.$d.API_ROOT_URL;
    201. this.selectGroupValue_sgAPI = this.getGroup_sgAPI(sgAPI).value;
    202. if (this.selectGroupValue_sgAPI === `custom`) {
    203. this.inputValue_sgAPI = sgAPI;
    204. }
    205. },
    206. getGroup_sgAPI(value) {
    207. let aa = this.selectGroupOptions_sgAPI;
    208. for (let i = 0, len = aa.length; i < len; i++) {
    209. let options = aa[i].options;
    210. let option = options.find((v) => v.value == value);
    211. if (option) return option;
    212. }
    213. return { value: `custom`, label: `其他` };
    214. },
    215. changeGroupSelect_sgAPI(d) {},
    216. valid(d) {
    217. if (this.selectGroupValue_sgAPI === `custom`) {
    218. if (!this.$g.checkEverything(`httpurl`, this.inputValue_sgAPI))
    219. return this.$message.error(`请输入正确的网址URL`);
    220. }
    221. },
    222. reload(d) {
    223. this.visible = false;
    224. location.reload(true);
    225. },
    226. reset(d) {
    227. delete localStorage.sgAPI;
    228. this.reload();
    229. },
    230. save(d) {
    231. if (this.valid()) return;
    232. if (this.selectGroupOptions_sgAPI === `custom`) {
    233. localStorage.sgAPI = this.inputValue_sgAPI;
    234. } else {
    235. localStorage.sgAPI = this.selectGroupValue_sgAPI;
    236. }
    237. this.reload();
    238. },
    239. oneClickRestore(d) {
    240. this.$confirm(
    241. `此操作将永久删除所有数据和配置信息,是否继续?`,
    242. `提示`,
    243. {
    244. dangerouslyUseHTMLString: true,
    245. confirmButtonText: `确定`,
    246. cancelButtonText: `取消`,
    247. type: "error",
    248. }
    249. )
    250. .then(() => {
    251. //this.$message.success(`删除成功`);
    252. this.$confirm(
    253. `请最后一次确认是否要删除所数据和配置信息?`,
    254. `提示`,
    255. {
    256. dangerouslyUseHTMLString: true,
    257. confirmButtonText: `确定`,
    258. cancelButtonText: `取消`,
    259. type: "error",
    260. }
    261. )
    262. .then(() => {
    263. this.dialogVisible_oneClickRestore = true;
    264. //this.$message.success(`删除成功`);
    265. })
    266. .catch(() => {
    267. //this.$message(`已取消删除`);
    268. });
    269. })
    270. .catch(() => {
    271. //this.$message(`已取消删除`);
    272. });
    273. },
    274. valid_oneClickRestore(d) {
    275. if (!this.psw) return this.$message.error("请输入密码");
    276. if (this.psw.length < 6) return this.$message.error("请输入正确的密码");
    277. },
    278. confirmRestore(d) {
    279. if (this.valid_oneClickRestore()) return;
    280. let data = {
    281. PSW: this.psw,
    282. sgLog: `前端请求来源:${this.$options.name}一键还原`,
    283. };
    284. this.$d.一键还原接口({
    285. data,
    286. r: {
    287. l: { show: () => (this.loading = true), close: () => (this.loading = false) },
    288. s: (d) => {
    289. this.dialogVisible = false;
    290. this.$message.success(`一键还原成功`);
    291. setTimeout(() => {
    292. this.$global.exit({ clearCookie: true });
    293. }, 1000);
    294. // console.log("【成功】", d);
    295. },
    296. },
    297. });
    298. },
    299. },
    300. };
    301. script>
    302. <style lang="scss" scoped>
    303. .api {
    304. }
    305. style>

    配置项

    1. // 开发者配置项----------------------------------------
    2. devConfig: {
    3. devPassword: `******`,//开发者密码
    4. sgAPI: [
    5. {
    6. label: '测试环境',
    7. options: [
    8. { value: `//shuzhiqiang.com:8088/rp`, label: '***环境名称' },
    9. { value: `//shuzhiqiang.com:8088/rp`, label: '***环境名称' },
    10. ],
    11. },
    12. {
    13. label: '生产环境',
    14. options: [
    15. { value: `//shuzhiqiang.com/api`, label: '***环境名称' },
    16. { value: `//shuzhiqiang.com:30107/api`, label: '***环境名称' },
    17. ]
    18. },
    19. {
    20. label: '其他',
    21. options: [
    22. { value: `custom`, label: '自定义' },
    23. ]
    24. },
    25. ]
    26. },

  • 相关阅读:
    SpringBoot第十三篇:同时集成华为RC6.5.1安全版kafka和原生kafka,通过配置文件动态控制
    Dubbo admin 快速搭建
    【UE4 反射系统】 UCLAS UFUNCTION UPROPERTY 宏简单解析 持续更新
    javascript 算术运算符,比较运算符 ,逻辑运算符
    CSS关于默认宽度
    申请与认证IB课程全流程
    《MongoDB》在docker中用得到关于MongoDB一行命令
    机器学习笔记 - sklearn随机森林(集成学习)
    web前端设计与开发期末作品 旅游咨询网站 HTML5期末大作业 HTML+CSS旅游社网站5个页面 关于制作网页主题论述
    NX二次开发-UFUN查询对象的类型和子类型UF_OBJ_ask_type_and_subtype
  • 原文地址:https://blog.csdn.net/qq_37860634/article/details/139806488