当前位置:   article > 正文

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

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

devOptions.vue源码

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/818903
推荐阅读
相关标签
  

闽ICP备14008679号