环境变量配置

  1. # 开发环境接口配置 /.env.development
  2. ENV = 'production'
  3. VUE_APP_BASE_URL = 'https://duanju.xun-hu.net'
  4. # 测试环境接口配置 /.env.test
  5. ENV = 'test'
  6. VUE_APP_BASE_URL = 'https://duanju.xun-hu.net'
  7. # 正式环境接口配置 /.env.production
  8. ENV = 'production'
  9. VUE_APP_BASE_URL = 'https://duanju.xun-hu.net'
  10. # 打包时区分不同环境打包
  11. npm run build:dev // 开发环境
  12. npm run build:test // 测试环境
  13. npm run build // 正式环境

可以根据业务需求,新增环境变量

使用:process.env.VUE_APP_BASE_URL

请求

  1. # /utils/request.js
  2. # 您可以根据实际的业务需求修改请求拦截器和响应拦截器
  3. // 请求拦截器
  4. service.interceptors.request.use(
  5. config => {
  6. config.header.key = 'abcd' // 自定义请求头,比如新增加密参数
  7. return config
  8. }
  9. )
  10. // 响应拦截器
  11. service.interceptors.response.use(
  12. response => {
  13. // 处理响应的业务逻辑
  14. return response.data
  15. },
  16. err => {
  17. // 处理响应的业务逻辑
  18. }
  19. )

ui组件

项目ui库使用的element-ui 2.15.12

基于element-ui二次开发的组件 /src/components/ui 您可以自己修改或增加

最佳实践

  1. <template>
  2. <ai-list class="list">
  3. <ai-title
  4. slot="title"
  5. title="账号管理"
  6. :isShowBottomBorder="true">
  7. </ai-title>
  8. <template slot="content">
  9. <ai-search-bar>
  10. <template #left>
  11. <el-button type="primary" size="medium" icon="iconfont iconAdd" @click="isShow = true">添加</el-button>
  12. </template>
  13. <template #right>
  14. <el-input
  15. v-model="search.search_value"
  16. class="search-input"
  17. size="medium"
  18. v-throttle="() => {search.current = 1, getList()}"
  19. placeholder="请输入用户名"
  20. clearable
  21. @clear="search.current = 1, search.search_value = '', getList()"
  22. suffix-icon="iconfont iconSearch">
  23. </el-input>
  24. </template>
  25. </ai-search-bar>
  26. <ai-table
  27. :tableData="tableData"
  28. :col-configs="colConfigs"
  29. :total="total"
  30. style="margin-top: 8px;"
  31. :current.sync="search.current"
  32. :size.sync="search.size"
  33. v-loading="isLoading"
  34. @getList="getList">
  35. <el-table-column slot="status" width="140px" label="状态" align="center">
  36. <template slot-scope="{ row }">
  37. <el-switch
  38. v-model="row.is_disable"
  39. :active-value="0"
  40. :inactive-value="1"
  41. @change="e => onChange(row.two_member_id, e)">
  42. </el-switch>
  43. </template>
  44. </el-table-column>
  45. <el-table-column width="160px" fixed="right" label="操作" align="center">
  46. <template slot-scope="{ row }">
  47. <div class="table-options">
  48. <el-button type="text" @click="edit(row)">编辑</el-button>
  49. <el-button type="text" @click="toStatistics(row.two_member_id)">数据统计</el-button>
  50. <el-button type="text" @click="remove(row)">删除</el-button>
  51. </div>
  52. </template>
  53. </el-table-column>
  54. </ai-table>
  55. <ai-dialog
  56. :title="id ? '编辑子账号' : '添加子账号'"
  57. width="790px"
  58. :visible.sync="isShow"
  59. customFooter
  60. @close="onClose">
  61. <el-form class="ai-form" :model="form" ref="form" label-width="80px">
  62. <el-form-item label="用户名" style="width: 100%;" prop="username" :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]">
  63. <el-input size="medium" placeholder="请输入用户名" v-model="form.username"></el-input>
  64. </el-form-item>
  65. <el-form-item label="昵称" style="width: 100%;" prop="nickname" :rules="[{ required: true, message: '请输入昵称', trigger: 'blur' }]">
  66. <el-input size="medium" placeholder="请输入昵称" v-model="form.nickname"></el-input>
  67. </el-form-item>
  68. <el-form-item label="密码" style="width: 100%;" prop="password" :rules="[{ required: id ? false : true, message: '请输入密码', trigger: 'blur' }]">
  69. <el-input size="medium" type="password" placeholder="请输入密码" v-model="form.password"></el-input>
  70. </el-form-item>
  71. <el-form-item label="手机号" style="width: 100%;" prop="phone">
  72. <el-input size="medium" placeholder="请输入手机号" v-model="form.phone"></el-input>
  73. </el-form-item>
  74. </el-form>
  75. <div class="dialog-footer" slot="footer">
  76. <el-button @click="isShow = false">取消</el-button>
  77. <el-button @click="onConfirm" type="primary" :loading="btnLoading">确定</el-button>
  78. </div>
  79. </ai-dialog>
  80. </template>
  81. </ai-list>
  82. </template>
  83. <script>
  84. export default {
  85. name: 'SubAccount',
  86. data () {
  87. return {
  88. search: {
  89. page: 1,
  90. limit: 10,
  91. search_field: 'username',
  92. search_exp: 'like',
  93. search_value: ''
  94. },
  95. form: {
  96. username: '',
  97. nickname: '',
  98. phone: '',
  99. password: ''
  100. },
  101. isLoading: false,
  102. isShow: false,
  103. colConfigs: [
  104. { prop: 'username', label: '名称' },
  105. { prop: 'nickname', label: '昵称', align: 'center' },
  106. { prop: 'phone', label: '手机号', align: 'center' },
  107. { prop: 'create_time', label: '注册时间', align: 'center' },
  108. { slot: 'status', align: 'center' }
  109. ],
  110. btnLoading: false,
  111. id: '',
  112. tableData: [],
  113. total: 0
  114. }
  115. },
  116. created () {
  117. this.getList()
  118. },
  119. methods: {
  120. getList () {
  121. this.isLoading = true
  122. this.$http.post(`/api/member.MemberTwo/list`, null, {
  123. params: {
  124. ...this.search
  125. }
  126. }).then(res => {
  127. if (res.code == 200) {
  128. this.tableData = res.data.list
  129. this.total = res.data.count
  130. }
  131. this.isLoading = false
  132. }).catch(() => {
  133. this.isLoading = false
  134. })
  135. },
  136. toStatistics (memberId) {
  137. this.$router.push(`/account/subAccountDetail?memberId=${memberId}`)
  138. },
  139. edit (e) {
  140. this.id = e.two_member_id
  141. this.form = {
  142. ...e
  143. }
  144. this.isShow = true
  145. },
  146. onClose () {
  147. this.id = ''
  148. this.form.nickname = ''
  149. this.form.username = ''
  150. this.form.phone = ''
  151. this.form.password = ''
  152. },
  153. onConfirm () {
  154. const api = this.id ? `/api/member.MemberTwo/edit` : '/api/member.MemberTwo/add'
  155. this.$refs.form.validate((valid) => {
  156. if (valid) {
  157. this.btnLoading = true
  158. this.$http.post(api, {
  159. ...this.form,
  160. two_member_id: this.id || ''
  161. }).then(res => {
  162. if (res.code === 200) {
  163. this.isShow = false
  164. this.$message.success(this.id ? '修改成功' : '添加成功')
  165. this.getList()
  166. this.id = ''
  167. }
  168. this.btnLoading = false
  169. }).catch(() => {
  170. this.btnLoading = false
  171. })
  172. }
  173. })
  174. },
  175. remove (e) {
  176. this.$confirm('确定删除该数据?').then(() => {
  177. this.$http.post(`/api/member.MemberTwo/dele`, {
  178. ids: [e.two_member_id]
  179. }).then(res => {
  180. if (res.code == 200) {
  181. this.$message.success('删除成功!')
  182. this.getList()
  183. }
  184. })
  185. })
  186. },
  187. onChange (userId, e) {
  188. this.$http.post(`/api/member.MemberTwo/disable`, {
  189. ids: [userId],
  190. is_disable: e
  191. }).then(res => {
  192. if (res.code == 200) {
  193. this.$message.success('操作成功!')
  194. this.getList()
  195. }
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style scoped lang="scss">
  202. </style>