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.

314 lines
11 KiB

1 year ago
12 months ago
1 year ago
1 year ago
12 months ago
1 year ago
12 months ago
1 year ago
12 months ago
1 year ago
7 months ago
1 year ago
12 months ago
12 months ago
1 year ago
12 months ago
1 year ago
7 months ago
12 months ago
7 months ago
12 months ago
7 months ago
1 year ago
12 months ago
1 year ago
12 months ago
1 year ago
12 months ago
12 months ago
1 year ago
12 months ago
12 months ago
12 months ago
1 year ago
12 months ago
1 year ago
  1. <template>
  2. <div class="user-add-or-update">
  3. <el-dialog
  4. width="530px"
  5. :title="!dataForm.id ? buttons.add :buttons.edit"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible">
  8. <!-- 取消 :rules="dataRule"-->
  9. <el-form :inline="true" :model="dataForm" label-position="top" ref="dataForm"
  10. @keyup.enter.native="dataFormSubmit()"
  11. label-width="80px">
  12. <el-form>
  13. <el-form-item :label="buttons.username||'用户账号'" prop="userName">
  14. <el-input v-model="dataForm.userName" style="width: 150px;" placeholder="登录帐号"></el-input>
  15. </el-form-item>
  16. <el-form-item :label="buttons.password||'密码'" prop="password" :class="{ 'is-required': !dataForm.id }">
  17. <el-input v-model="dataForm.password" style="width: 150px;" type="password" ></el-input>
  18. </el-form-item>
  19. <el-form-item :label="buttons.comfirmPassword||'确认密码'" prop="comfirmPassword" :class="{ 'is-required': !dataForm.id }">
  20. <el-input v-model="dataForm.comfirmPassword" style="width: 150px;" type="password"
  21. ></el-input>
  22. </el-form-item>
  23. </el-form>
  24. <el-form>
  25. <el-form-item :label="buttons.userDisplay||'用户名'" prop="email">
  26. <el-input v-model="dataForm.userDisplay" style="width: 150px;" ></el-input>
  27. </el-form-item>
  28. <el-form-item :label="buttons.domainAccount||'域控账号'" prop="domainAccount">
  29. <el-input v-model="dataForm.domainAccount" style="width: 150px;" placeholder="域控账号"></el-input>
  30. </el-form-item>
  31. <el-form-item :label="buttons.email||'邮箱'" prop="email">
  32. <el-input v-model="dataForm.email" style="width: 150px;" ></el-input>
  33. </el-form-item>
  34. <el-form-item :label="buttons.mobile||'手机号'" prop="mobile">
  35. <el-input v-model="dataForm.mobile" style="width: 150px;" placeholder="手机号"></el-input>
  36. </el-form-item>
  37. <el-form-item :label="buttons.language||'语言'" prop="languageDefault">
  38. <el-select filterable v-model="dataForm.languageDefault" clearable style="width: 150px;">
  39. <el-option :label="item.languageName" :value="item.languageCode" v-for="(item,index) in languageList "
  40. :key="index"></el-option>
  41. </el-select>
  42. </el-form-item>
  43. </el-form>
  44. <el-form>
  45. <el-form-item :label="buttons.site||'工厂'" size="mini" prop="siteList">
  46. <el-checkbox-group v-model="dataForm.siteList">
  47. <el-checkbox v-for="site in siteOptions" :key="site.key" :label="site.key">{{
  48. site.label
  49. }}
  50. </el-checkbox>
  51. </el-checkbox-group>
  52. </el-form-item>
  53. </el-form>
  54. <el-form>
  55. <el-form-item label="角色" size="mini" prop="roleIdList">
  56. <el-checkbox-group v-model="dataForm.roleIdList">
  57. <el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{
  58. role.roleName
  59. }}
  60. </el-checkbox>
  61. </el-checkbox-group>
  62. </el-form-item>
  63. </el-form>
  64. <el-form>
  65. <el-form-item label="状态" size="mini" prop="status">
  66. <el-radio-group v-model="dataForm.status">
  67. <el-radio :label="0">{{buttons.disable||'禁用'}}</el-radio>
  68. <el-radio :label="1">{{buttons.normal||'正常'}}</el-radio>
  69. </el-radio-group>
  70. </el-form-item>
  71. </el-form>
  72. </el-form>
  73. <span slot="footer" class="dialog-footer">
  74. <el-button type="primary" @click="dataFormSubmit()">{{buttons.submit||'确定'}}</el-button>
  75. <el-button @click="visible = false">{{buttons.close||'取消'}}</el-button>
  76. </span>
  77. </el-dialog>
  78. <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
  79. </div>
  80. </template>
  81. <script>
  82. import Chooselist from '@/views/modules/common/Chooselist'
  83. import {searchSysLanguage} from "@/api/sysLanguage.js"
  84. import {getUserAccessSiteList, saveUserAccessSiteList, getUserAuthorizedSites} from "@/api/factory/accessSite.js"
  85. import {
  86. searchFunctionButtonList,
  87. } from "@/api/sysLanguage.js"
  88. export default {
  89. components: {
  90. Chooselist
  91. },
  92. data() {
  93. return {
  94. tagNo:'',
  95. visible: false,
  96. roleList: [],
  97. factorys: [],
  98. languageList: [],
  99. siteOptions: [], // 工厂选项列表
  100. dataForm: {
  101. id: 0,
  102. userName: '',
  103. password: '',
  104. comfirmPassword: '',
  105. languageDefault: 'cn',
  106. salt: '',
  107. email: '',
  108. mobile: '',
  109. roleIdList: [],
  110. status: 1,
  111. site: '', // 保持兼容性
  112. siteList: [], // 多选工厂列表
  113. userDisplay: '',
  114. domainAccount: ''
  115. },
  116. buttons: {
  117. add: '添加',
  118. edit: '编辑',
  119. username: '用户账号',
  120. userDisplay: '用户名',
  121. domainAccount: '域控账号',
  122. email: '邮箱',
  123. mobile: '手机号',
  124. status: '状态',
  125. disable: '禁用',
  126. normal: '正常',
  127. password:'密码',
  128. comfirmPassword:'确认密码',
  129. submit: '确定',
  130. close: '取消',
  131. site: '工厂',
  132. language: '语言',
  133. },
  134. }
  135. },
  136. methods: {
  137. getFunctionButtonList() {
  138. let queryButton = {
  139. functionId: this.$route.meta.menuId,
  140. tableId: '*',
  141. languageCode: this.$i18n.locale,
  142. objectType: 'button'
  143. }
  144. searchFunctionButtonList(queryButton).then(({data}) => {
  145. if (data.code == 0 && data.data) {
  146. this.buttons = data.data
  147. }
  148. })
  149. },
  150. getBaseData(val){
  151. if (this.tagNo === 93){
  152. this.dataForm.site = val.SiteID
  153. }
  154. },
  155. // 获取基础数据列表
  156. getBaseList(val){
  157. this.tagNo = val
  158. this.$nextTick(() => {
  159. let strVal = "";
  160. if (val === 93){
  161. strVal = this.dataForm.site
  162. }
  163. this.$refs.baseList.init(val,strVal)
  164. })
  165. },
  166. // 获取多语言列表
  167. getLanguageList() {
  168. let queryLanguage = { languageCode: this.$i18n.locale}
  169. searchSysLanguage(queryLanguage).then(({data}) => {
  170. this.languageList = data.rows
  171. })
  172. },
  173. init(id) {
  174. this.dataForm.id = id || 0
  175. // 如果是新增模式,清空表单数据
  176. if (!this.dataForm.id) {
  177. this.dataForm = {
  178. id: 0,
  179. userName: '',
  180. password: '',
  181. comfirmPassword: '',
  182. languageDefault: 'cn',
  183. salt: '',
  184. email: '',
  185. mobile: '',
  186. roleIdList: [],
  187. status: 1,
  188. site: '',
  189. siteList: [],
  190. userDisplay: '',
  191. domainAccount: ''
  192. }
  193. }
  194. // this.factoryList();
  195. this.getLanguageList();
  196. this.getSiteOptions(); // 获取工厂选项
  197. this.$http({
  198. url: this.$http.adornUrl('/sys/role/select'),
  199. method: 'get',
  200. params: this.$http.adornParams()
  201. }).then(({data}) => {
  202. this.roleList = data && data.code === 0 ? data.list : []
  203. }).then(() => {
  204. this.visible = true
  205. this.$nextTick(() => {
  206. this.$refs['dataForm'].resetFields()
  207. })
  208. }).then(() => {
  209. if (this.dataForm.id) {
  210. // 编辑模式:加载用户数据
  211. this.$http({
  212. url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.id}`),
  213. method: 'get',
  214. params: this.$http.adornParams()
  215. }).then(({data}) => {
  216. if (data && data.code === 0) {
  217. this.dataForm.userName = data.user.username
  218. this.dataForm.salt = data.user.salt
  219. this.dataForm.email = data.user.email
  220. this.dataForm.mobile = data.user.mobile
  221. this.dataForm.roleIdList = data.user.roleIdList
  222. this.dataForm.status = data.user.status
  223. this.dataForm.languageDefault = data.user.languageDefault
  224. this.dataForm.site = data.user.site.toString()
  225. this.dataForm.userDisplay = data.user.userDisplay
  226. this.dataForm.domainAccount = data.user.domainAccount
  227. // 获取用户工厂权限
  228. this.getUserSiteAccess(data.user.username)
  229. }
  230. })
  231. }
  232. })
  233. },
  234. // 表单提交
  235. dataFormSubmit() {
  236. this.$refs['dataForm'].validate((valid) => {
  237. if (valid) {
  238. // 保存用户信息和工厂授权(在一个事务中)
  239. this.$http({
  240. url: this.$http.adornUrl(`/sys/user/${!this.dataForm.id ? 'save' : 'update'}`),
  241. method: 'post',
  242. data: this.$http.adornData({
  243. 'userId': this.dataForm.id || undefined,
  244. 'username': this.dataForm.userName,
  245. 'password': this.dataForm.password,
  246. 'salt': this.dataForm.salt,
  247. 'email': this.dataForm.email,
  248. 'mobile': this.dataForm.mobile,
  249. 'status': this.dataForm.status,
  250. 'roleIdList': this.dataForm.roleIdList,
  251. 'languageDefault': this.dataForm.languageDefault,
  252. 'site': this.dataForm.site,
  253. 'userDisplay': this.dataForm.userDisplay,
  254. 'domainAccount': this.dataForm.domainAccount,
  255. 'siteList': this.dataForm.siteList || [] // 添加工厂授权列表
  256. })
  257. }).then(({data}) => {
  258. if (data && data.code === 0) {
  259. this.$message.success('操作成功')
  260. this.visible = false
  261. this.$emit('refreshDataList')
  262. } else {
  263. let msg = data.msg.split('<br>')[0]
  264. this.$message.error( this.$t(`${msg}`))
  265. }
  266. })
  267. }
  268. })
  269. },
  270. // 获取工厂选项列表
  271. getSiteOptions() {
  272. // 使用site接口获取工厂列表
  273. this.$http({
  274. url: this.$http.adornUrl('/site/list'),
  275. method: 'post',
  276. data: this.$http.adornData({
  277. active: 'Y' // 只获取激活的工厂
  278. })
  279. }).then(({data}) => {
  280. if (data && data.code === 0) {
  281. this.siteOptions = data.dataList || []
  282. }
  283. }).catch(() => {
  284. this.$message.error('获取工厂列表失败')
  285. })
  286. },
  287. // 获取用户工厂权限
  288. getUserSiteAccess(username) {
  289. if (!username) return
  290. getUserAuthorizedSites({ userName: username }).then(({data}) => {
  291. if (data && data.code === 0) {
  292. // 数据结构: [{siteCode: 'F001', siteName: '工厂A'}, ...]
  293. this.dataForm.siteList = data.data ? data.data.map(item => item.siteCode) : []
  294. }
  295. }).catch(() => {
  296. this.$message.error('获取用户工厂权限失败')
  297. })
  298. }
  299. },
  300. created() {
  301. this.getFunctionButtonList()
  302. }
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. </style>